From: tim Date: 2004-02-11T10:40:09+09:00 Subject: Re: running a class from the base class Shashank Date wrote: > "tim" wrote in message > >>I currently have a number of derived classes that all >>have something like: >> >>begin >> xx = SpecificArchitecture.new() >> xx.main(ARGV) >>end >> >>at the end. Which i would like to remove. > > ^^^^^^^^ > If you always want to do this _at the end_ of your program, > then take a look at the Kernel#at_exit {} method. > > -- shanko > > thanks -- yes after more spelunking through the test stuff we now have something like this: ============ file 1 =========== require 'y' class X < Y def blah print 'in blah' end end =========== file 2 ============ class Y def self.run() ::ObjectSpace::each_object(Class) do |class_object| # we only want classes that are above this one... if (Y > class_object) instance = class_object.new() instance.blah() end end end at_exit{ exit(Y.run()) } ================================== I am sure that there are some subtly gothca's in this but it does mean that all of my X classes now don't have to have: begin instance = X.new() instance.blah() end on them all. Theses are obviously much cut down examples -- there is a lot more cruft in all real implementations...