Ruby class types and case statements

Yeah, Nakilon is correct, you must know how the threequal === operator works on the object given in the when clause. In Ruby

case item
when MyClass
...
when Array
...
when String
...

is really

if MyClass === item
...
elsif Array === item
...
elsif String === item
...

Understand that case is calling a threequal method (MyClass.===(item) for example), and that method can be defined to do whatever you want, and then you can use the case statement with precisionw


You must use:

case item
when MyClass
...

I had the same problem: How to catch Errno::ECONNRESET class in "case when"?