Alle 18:33, luned4 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
Stefano