Chuck Remes
12/4/2006 5:58:00 PM
On Monday, December 04, 2006, at 11:44AM, "Stefano Crocco" <stefano.crocco@alice.it> wrote:
>Alle 18:33, lunedì 4 dicembre 2006, cremes.devlist@mac.com ha scritto:
>> def case_test(obj)
>> print "testing via case... "
>> case obj.class
>> when Array
>> puts "obj is a #{obj.class}"
>> when String
>> puts "obj is a #{obj.class}"
>> else
>> puts "obj is unknown: #{obj.class}"
>> end
>> end
>
>Your code will call Array===obj.class. According to ri aClass===anObject
>returns true if anObject is an instance of aClass or of one of its
>descentents (which more or less means if anObject.is_a?(aClass) returns
>true). Because of this, all your 'when' statements will fail, because
>obj.class is not an instance of Array or String. To do what you want, you
>should substitute
>
> case obj.class
>
>with
>
> case obj
Sheesh! I *knew* it was something easy. I feel like a dope...
cr