While learning Ruby I stumbled across something I don’t understand:
Object === Object
=> true
String === String
=> false
Can anyone tell me, why Ruby behaves this way?
Module#=== (which is what you are calling in both examples) returns true
if the parameter (the one on the right-hand side of the ===) is an instance
of the module (on the left-hand side) or one of its descendants. Since the
class String is not an instance of the class string, this is false. The
reason that the first example is true is because virtually everything in
Ruby is an instance of class Object.