Ruby :: Ancestor Chain

Always wondered how to see Ruby’s class hierarchy? Simply call ancestors on a class to see the ancestor chain.

The return array contains the following order:

  • the calling class
  • its included modules
  • its parent class
  • the included modules of its parents class
  • the parent class of its parent class

Here is the ancestor chain of the String class:

irb> String.ancestors
 => [String, Comparable, Object, Kernel, BasicObject]
Additional links

Leave a Reply

Your email address will not be published. Required fields are marked *

*