how to get all inherited class names ?
It’s no that what you want but maybe it will help you:
a.class #=> return class
a.class.superclass #=>return superclass of class. Example:
class A
def a
“a”
end
end
class B < A
def b
“b”
end
end
beta = B.new
b.class.superclass #=> A
2008/3/20, Pokkai D. [email protected]:
On Thu, Mar 20, 2008 at 1:39 PM, Pokkai D. [email protected]
wrote:
how to get all inherited class names ?
Class helper functions
class Class
Iterates over all subclasses (direct and indirect)
def each_subclass
ObjectSpace.each_object(Class) { | candidate |
yield candidate if candidate < self
}
end
Returns an Array of subclasses (direct and indirect)
def subclasses
ret = []
each_subclass {|c| ret << c}
ret
end
Returns an Array of direct subclasses
def direct_subclasses
ret = []
each_subclass {|c| ret << c if c.superclass == self }
ret
end
end
On 20.03.2008 13:39, Pokkai D. wrote:
how to get all inherited class names ?
irb(main):001:0> Fixnum.superclass
=> Integer
irb(main):002:0> Fixnum.ancestors
=> [Fixnum, Integer, Precision, Numeric, Comparable, Object, Kernel]
irb(main):003:0>
robert