From: Dave Thomas Date: 2001-02-28T14:06:43+09:00 Subject: [ruby-talk:11742] Re: Subclasses of a Class? Ron Jeffries writes: > I'm wanting to set up RubyUnit to automatically run all the suites of > all the subclasses of RUNIT::TestCase, but there doesn't seem to be a > way to get all subclasses of a class ... or I can't find it. > > Is there? What is it? Or is there another way to get all the suites? Ron: You can add support to RUNIT::TestCase using the 'inherited' method (http://www.rubycentral.com/book/ref_c_class.html#inherited) like this: class TestCase @@subclasses = [] def TestCase.inherited(by) @@subclasses << by end def TestCase.subclasses @@subclasses end end class B < TestCase; end class C < TestCase; end class D < B; end class E; end p TestCase.subclasses #=> [B, C, D] (I cheated and called this example TestCase because I didn't drag RUnit in). Regards Dave