From: Lyle Johnson Date: 2004-01-29T06:04:52+09:00 Subject: Re: Type Noixe wrote: > Is there a method to know a type of object? > > For example: > > x = 1 > y = [1, 2, 3] > z = {1 => "one", 2 => "two"} > > > puts x.type # Must print "int" > puts x.type # Must print "array" > puts x.type # Must print "hash" You made a very good guess ;) puts x.type # prints "Fixnum" puts y.type # prints "Array" puts z.type # prints "Hash" Note that for Ruby 1.8, the type() method is deprecated and you should use class() instead, i.e. puts x.class # prints "Fixnum" puts y.class # prints "Array" puts z.class # prints "Hash" Hope this helps, Lyle