about Ruby:

String === String # => false

Meaning:

x = String

result = case x
when String then "got a string"
else “not a string"
end

result # => not a string

I guess I figured === would always be true for equality, but I guess not?

Of note, "foo" === "foo” # => true

Weird.

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

@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
7mo
Replies