0

I'm analyzing a bit of how the three equal sign ===, or case equality method/operator works on Ruby for true, false, TrueClass and FalseClass. And I found this particular behavior/result when evaluating these expressions:

> TrueClass === true
# => true

> true === TrueClass
# => false

I know each object has its own implementation of this, such as string where:

variable === 'abc'

In case of true would mean, variable matches 'abc' exactly, false otherwise.

The implementation I see of this in C doesn't really tell me anything as I'm not very familiar with Ruby's C implementation. Here's the link: http://ruby-doc.org/core-2.3.0/TrueClass.html#method-i-3D-3D-3D

Thanks in advance.

  • 3
    Also my own answer in [How does the === work in ruby?](https://stackoverflow.com/questions/29405018/how-does-the-work-in-ruby), and Jörg W Mittag's insight that `===` is *not* case equality, but case *subsumption*. `true === TrueClass` invokes `TrueClass#===` (equality); `TrueClass === true` invokes `Module#===`, which tests if rhs is an instance of lhs or one of its descendants. – Amadan Aug 26 '16 at 05:55
  • I suspect you asked this question because `a == b` if and only if `b == a`, and `==` and `===` have a similar appearance. The latter, however, like most Ruby methods, is not symmetric and bears only a slight connection to the former. Had the method `===` instead been named `catnip`, would you be asking? – Cary Swoveland Aug 26 '16 at 06:00
  • The answer described in [here](https://stackoverflow.com/questions/29405018/how-does-the-work-in-ruby) is just what I was looking for. Thanks a loot. Clearly explained! – sebasjimenez10 Aug 26 '16 at 06:10

0 Answers0