Class` descendants
Posted by Sergey Enin 05 August 2011 at 18:12
Sometimes, it is neccessary to build tree of some class subclasses. For example when plugins in ruby application inherit from some Class and you want to control it. For that purpose you should use ObjectSpace.each_object.
I placed example below, to use it you need:
1) Object.class_eval("extend ClassModule")
2) and now you can simply Numeric.subclasses or Numeric.successors
For example, I runned it on my machine(excluded some Gem, RubyVM and other special classes) to get Tree of all Classes avaible for RubyVM at current time:
or if you prefer images:
you can get it.
ActiveRecord tracking
If you want tracking of creating classes, you can extend ActiveSupport::DescendantsTracker module.
After it you classes will start to watch after the descendants.
Thanks for that info.
Thank you.

