Ruby Rabbit wrote: > I stored the class of a variable in a variable and later checked in a > switch-case. Instead of going into the Fixnum case, it goes into ELSE. > > c=23.class # => Fixnum > > c == Fixnum # => true > > case c; when Fixnum; puts "YES"; else; puts "NO"; end > > # => prints NO > > # after much head-scratching tried this: > > case c; when Fixnum; puts "YES"; when Class; puts "CLASS"; else; puts > "NO"; end > > # prints CLASS > > --- > As a result of this I had to store the class as a string (to_s), so the > case could work. > Could someone explain what I am missing here. > Thx. > Case statements do not use the equality operator (==), they use the "relationship operator" (===), which is typically not commutative. Also, the value in the "when" part is the left-hand value (not the right-hand value, as you might expect). Futhermore, Class objects (like Fixnum) use Module's definition of "===", which returns true if the right-hand side is an instance of the module or one of its descendents. Therefore: irb(main):001:0> c = 32.class => Fixnum irb(main):002:0> Fixnum === c => false irb(main):003:0> Fixnum === Fixnum => false irb(main):004:0> Fixnum === 23 => true -Justin