Ruby/Reflection/superclass

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Get class and superclass

o = "test"  # This is a value
o.class     # Returns an object representing the String class
o.class.superclass            # Object: superclass of String is Object
o.class.superclass.superclass # nil: Object has no superclass



Get superclass

p String.superclass         # => Object



Object has a super class in Ruby 1.9

# Ruby 1.9 only
Object.superclass             # BasicObject: Object has a superclass in 1.9
BasicObject.superclass        # nil: BasicObject has no superclass