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 comparisons are done using ===, so this is the same as if Hacker === obj ... (and so on). The === method of Class is inherited from Module, and is documented as:
"Returns true if obj is an instance of module or one of module 's descendants. Of limited use for modules, but can be used in case statements to classify objects by class."
So it's also asymmetric - "k" === String is false, but String === "k" is true.
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 →
case comparisons are done using
===
, so this is the same asif Hacker === obj ...
(and so on). The===
method ofClass
is inherited fromModule
, and is documented as:"Returns true if obj is an instance of module or one of module 's descendants. Of limited use for modules, but can be used in case statements to classify objects by class."
So it's also asymmetric -
"k" === String
is false, butString === "k"
is true.