From: Joel VanderWerf Date: 2009-08-13T04:39:20+09:00 Subject: Re: Class#descendants? 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] > > Thank you. irb(main):001:0> ObjectSpace.each_object(Class) {|cl| p cl if cl < Numeric} Bignum Float Fixnum Integer But keep in mind: it's inefficient (so cache if you can), and it may not be standard across rubies (jruby may not have it IIRC). It's useful for interactive poking around though. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407