Ruby - Finding An Object's Ancestor Classes

Introduction

Ultimately all classes descend from the Object class.

In Ruby 1.9, the Object class itself descends from the BasicObject class.

Demo

def showFamily( aClass ) 
    if (aClass != nil) then     
        puts( "#{aClass} :: about to recurse with aClass.superclass =  
        #{aClass.superclass.inspect}" ) 
        showFamily( aClass.superclass ) 
    end #   w w  w  .  j  a  v  a  2  s. c  om
end 
showFamily(File)

Result

Related Topic