Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 8. Reflection and Metaprogramming > Types, Classes, and Modules

8.1. Types, Classes, and Modules

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

Returns the class of an object o.


c.superclass

Returns the superclass of a class c.


o.instance_of? c

Determines whether the object o.class == 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

kind_of? is a synonym for is_a?.


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.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint