I'm using Ruby's case
syntax to set up some simple logic based on self.class
as follows:
case self.class
when FirstClass
do stuff....
when SecondClass
do other stuff...
end
I soon realized this always returns nil.
Upon closer investigation, I found that case
uses ===
rather than ==
to check equality. When running self.class == FirstClass
in my terminal I get true
as expected, however self.class === FirstClass
returns false
.
Looking into the ruby docs, I found the following explanation of ===
:
Case Equality – For class Object, effectively the same as calling #==, but typically overridden by descendants to provide meaningful semantics in case statements.
Can anyone out there shed some light on what may be happening? Thanks in advance.