We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Case equality (success by a when candidate) is determined by the case-equality or “threequal” operator, ===.
So you know this already, because you are specifically mentioning
There is something I can't figure out about the === operator when applied to Classes...
But did you know that:
=== is typically overriden by classes to reflect meaningful case-statement behavior; for example, /abc/ === "string" checks for a pattern match from the string.
In fact, if you actually go and look at the Ruby documentation on the Class class, you'll notice that it doesn't have a definition of ===. This behavior is delegated to Object
So when you execute the following:
caseobj.classwhenHackerputs"It's a Hacker!"...
You're comparing the Class of HackerRank (which is a class) to the Class Hacker via the === operator.
You can verify this by calling obj.class.class because the curried .class is what is being compared with the case statement
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby Control Structures - Case (Bonus Question)
You are viewing a single comment's thread. Return to all comments →
From the Ruby documentation:
So you know this already, because you are specifically mentioning
But did you know that:
In fact, if you actually go and look at the Ruby documentation on the Class class, you'll notice that it doesn't have a definition of
===
. This behavior is delegated to ObjectSo when you execute the following:
You're comparing the
Class
ofHackerRank
(which is a class) to theClass
Hacker via the===
operator.You can verify this by calling
obj.class.class
because the curried.class
is what is being compared with thecase
statement