From: Christopher Dicely Date: 2008-02-10T07:25:42+09:00 Subject: Re: Identifying On Feb 9, 2008 2:14 PM, Adam Akhtar wrote: > Farrel Lifson wrote: > > > Use a case statement: > > > > array.each do |x| > > case x > > when Array: do something > > when Integer: do something > > end > > end > > is > > when Array: do something > > a valid statement?? Yes. "when" uses the === method of the object given, and Array is a constant instance of class Class, and Class#===(obj) (inherited from Module) is equivalent to obj.kind_of?(self) > > is > > if x == Array > > also a valid statement?? x == Array is a *valid* statement, but it doesn't mean the same thing. case x when Array: ... end is the same as: if Array === x then ... end not: if x == Array then ... end > i was expecting having to use something like x.is_a as Stefano said. As is oft the case with Ruby, there is more than one way to do it.