From: Christophe Grandsire Date: 2005-10-26T00:06:15+09:00 Subject: Re: Comparing Classes with Case ? Selon Warren Seltzer : > The following failure surprised me: > > Version 1: > > irb(main):068:0> "hi".class == "hi".class > => true > irb(main):069:0> "hi".class === "hi".class > => false > > > Version 2: > > irb(main):055:0> case "whatever".class > irb(main):056:1> when String > irb(main):057:1> p "it is a string" > irb(main):058:1> else > irb(main):059:1* p "it is not a string" > irb(main):060:1> end > "it is not a string" > > What it amounts to is you can't use case/when to test for class. This is a > HUGE LOSE. > The pickaxe book .chm says YOU CAN do it. I'm using ruby 1.8.2 > Lose the ".class". === automatically looks for the class of the left argument. In your case example, just write: case "whatever" when String p "it is a string" else p "it is not a string" end It's work like a charm. Basically "a === SomeClass" is the same as "a.class == SomeClass". -- Christophe Grandsire. http://rainbow.conlang.free.fr It takes a straight mind to create a twisted conlang.