I wanted to do some decision on a variable class type so I wrote this:
case variable.class
when Fixnum, Float
puts “It’s a Fix or Float”
when String
puts “It’s a String”
end
It took me 2 hours to realize that ‘case’ and the underlying ‘===’ won’t
work here:
[26] pry(main)> a = 1.2
=> 1.2
[27] pry(main)> a.class
=> Float
[28] pry(main)> a.class == Float
=> true
[29] pry(main)> a.class === Float
=> false
based on documentation, ‘===’ should be smarter than ‘==’.
Did I miss something here?