I do the following, and it evaluates to false:
MyObject.new.class === MyObject
However,
MyObject.new.class == MyObject
evaluates to true. Can someone with a bit more Ruby background explain this to me, and if it’s okay to use == for this purpose?
In Ruby,
===isn’t a stricter version of==, as it is in some other languages.The
===method has several meanings:Membership:
Test whether the argument is an instance of the receiver:
Regex match:
Case statements:
Other meanings, see
ri ===MyObject.new.class == MyObjectis just a normal equality test (MyObject is a class object, and MyObject.new.class is the same class object)