[Solved] How does the === work in ruby? [duplicate]


Because

  • String === 'a' is the same as String.===('a'), which calls Class#===, inherited from Module#=== to test whether the parameter inherits from the receiver module; and

  • 'a' === String is the same as 'a'.===(String), which calls String#===, inherited from Object#=== to test whether the parameter is equal to the receiver object.

In other words, === is not symmetric; Object#=== and Module#=== are very different methods. There’s also Regexp#===, Proc#===… that also do very different things, and are also asymmetric (match against pattern, execute with parameter(s)).

0

solved How does the === work in ruby? [duplicate]