Reputation: 16081
In ruby I can find the class of an object by calling the 'class' method:
5.class
'foo'.class
3.14.class
How do I find the superclass?
Upvotes: 1
Views: 954
Reputation: 29349
this should work
5.class
=> Fixnum
5.class.superclass
=> Integer
You can also use ancestors method which will give you a list of all the superclasses
5.class.ancestors
=> [Fixnum, Integer, Numeric, Comparable, Object, Kernel, BasicObject]
Upvotes: 4
Reputation: 11212
You can use .superclass
like:
3.14.class.superclass
More info about that mhetod you can find here.
Upvotes: 3
Reputation: 10074
You call the superclass
method on the class
2.1.2 :003 > 5.class.superclass
=> Integer
Upvotes: 2