Yes is no and no is yes

During a regular Perl vs Ruby debate, I experimented with redefining truth in Ruby.

George Bashi 20 June 2013
This is an article from Semantico Labs, the R&D department of the digital publishing solutions company.


Due to Ruby’s “open classes”, it’s fairly easy to redefine anything in the standard library, including base classes like true and false. Unfortunately, as this StackOverflow answer touches on, some of the logic around true and false is baked into the language and so unmodifiable (at least in MRI - I’m yet to try with Rubinius et al). I had a play in Pry and managed to redefine == on true and false, which leads to some nice weirdness, but probably wouldn’t affect the behavior of control statements like if (which use the built in truthiness).

Check out the asciicast below: