From: Robert Klemme Date: 2009-08-13T04:50:06+09:00 Subject: Re: Class#descendants? On 12.08.2009 21:30, Jason Lillywhite wrote: > Ruby can do Class#ancestors but not Class#descendants. > > I found this: http://termos.vemod.net/class-descendants > > But it only works after you define a new inheritance. Is there a way to > find descendants of a class that is already in place? For example: > > Numeric.descendants > => [Integer, Float, Complex] Let me first state that I believe this is intentional: while sub classes need knowledge of their parent classes the opposite is not true. In fact, that would create a kind of circular dependency. Having said that, this is what you could do require 'set' h = Hash.new {|h,k| h[k] = Set.new} ObjectSpace.each_object(Class) do |cl| cl.superclass.ancestors.each {|scl| h[scl] << cl} end p h[String] You should keep in mind though that this is by no means static. New classes can come in existence at any time. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/