From: luke gruber Date: 2011-10-06T11:45:28+09:00 Subject: Re: How to output an instance's type >How do I output the type of a variable? In Ruby, the type is not really synonymous with the object's class, but has more to do with the methods the object responds to. So normally Rubyists use class to mean the Class, and 'type' is sort of a grey-area word. But, more practically, object.methods will return all the methods that object responds to. object.class.instance_methods(false) will return all methods the object responds to that were defined in its class but not its class's superclass(es). object.respond_to? :methodname will return true/false depending whether or not the object responds to that method name. object.class.ancestors will return an array of the inheritance chain of the object's class (superclasses and mixed in modules). There's also object.is_a? ClassName, which is kind of like the 'type' of an object, in that it will respond true if ClassName is a superclass of object's class (or mixed in module). And finally, object.instance_of? ClassName checks if ClassName is the direct class, but not superclass, of object. Hope that helps! (and sorry for the length...) -Luke -- Posted via http://www.ruby-forum.com/.