You are viewing a single comment's thread. Return to all comments →
There is something I can't figure out about the === operator when applied to Classes...
===
Why does "123".class == String returns true while "123.class === String returns false?
"123".class == String
"123.class === String
My first idea in this problem was to write
case obj.class when Hacker puts "It's a Hacker!"
etc... But since the === doesn't behave the way I thought it would, I wrote instead
case obj.class.to_s when 'Hacker' puts "It's a Hacker!"
etc... This way of doing thing seems a little "hacky" to me though... would anyone shed some light on the subtlelties I'm missing?
Ruby Control Structures - Case (Bonus Question)
You are viewing a single comment's thread. Return to all comments →
There is something I can't figure out about the
===
operator when applied to Classes...Why does
"123".class == String
returns true while"123.class === String
returns false?My first idea in this problem was to write
etc... But since the
===
doesn't behave the way I thought it would, I wrote insteadetc... This way of doing thing seems a little "hacky" to me though... would anyone shed some light on the subtlelties I'm missing?