Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The most commonly used reflective methods are those for determining the type of an object—what class it is an instance of and what methods it responds to. We introduced most of these important methods early in this book in Section 3.8.4. To review:
o.class
c.superclass
o.instance_of? c
o.is_a? c
Determines whether o is an instance of c, or of any of its subclasses. If c is a module, this method tests whether o.class (or any of its ancestors) includes the module.
o.kind_of? c
c === o
For any class or module c, determines if o.is_a?(c).
o.respond_to? name
Determines whether the object o has a public or protected method with the specified name. Pass true as the second argument to check private methods as well.