r/ProgrammerHumor 17h ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.4k Upvotes

262 comments sorted by

View all comments

11

u/SleepingInsomniac 15h ago

In Ruby, everything is an object. 0 is just an instance of Integer. Object instances are truthy, compared to say, nil. Makes more sense than ( 'b' + 'a' + + 'a' + 'a' ).toLowerCase() === "baNaNa" or 1 + '0' == '10' or NaN === Nan; // false

0

u/prehensilemullet 13h ago

Hmm, let’s look at what you’re saying

A:  In Ruby, everything is an object. 0 is just an instance of Integer.

Huh, I guess false must be an object of some kind

B:  Object instances are truthy, compared to say, nil

Well A and B would mean that false is truthy, so one of the two can’t be right

3

u/SleepingInsomniac 12h ago edited 12h ago

The global value false is the only instance of class FalseClass and represents a logically false value in boolean expressions. The class provides operators allowing false to participate correctly in logical expressions.

https://docs.ruby-lang.org/en/master/FalseClass.html

ruby false.methods - Object.methods # => [:&, :|, :^]

Edit: I should add that the if keyword just literally checks if the value is false or nil.