Because
-
String === 'a'
is the same asString.===('a')
, which callsClass#===
, inherited fromModule#===
to test whether the parameter inherits from the receiver module; and -
'a' === String
is the same as'a'.===(String)
, which callsString#===
, inherited fromObject#===
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]