@davetron5000 IIRC, === on class Class is defined by class membership.

The default implementation of === is an alias of ==, but a few classes redefine it. You'll also get something surprising with instances of class Regex, too, because it's overridden to mean regex match.

irb(main):003:0> /a/ == /a/
=> true
irb(main):001:0> /a/ === /a/
=> false
irb(main):002:0> /a/ === 'a'
=> true

1
Share
Share on Mastodon
Share on Twitter
Share on Facebook
Share on Linkedin
Randy Elzinga

@davetron5000 I only learned this myself recently after reading about it in the latest edition of Programming Ruby from @noelrap and doing a bit of experimentation.

0
8mo
Replies