From: Robert Dober Date: 2007-07-24T17:02:31+09:00 Subject: Re: Inherited & load On 7/24/07, F. Senault wrote: > Hello. > > I've written a mechanism to dynamically load plugins inheriting from a > base class, using the self.inherited method. > > Now, in an irb session, I noticed that, even if I (re)load the classes, > the self.inherited is only triggered once. Short example : > > > ruby -v > ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6] > > > cat first.rb > #! /usr/local/bin/ruby > load "test.rb" > load "test.rb" > > > cat test.rb > #! /usr/local/bin/ruby > class Test > def self.inherited(c) > puts "#{c} inherited Test !" > end > end > load "test2.rb" > > > cat test2.rb > #! /usr/local/bin/ruby > puts "In #{__FILE__}." > class Test2 < Test ; end > > > ruby first.rb > In ./test2.rb. > Test2 inherited Test ! > In ./test2.rb. > > Is there a trick somewhere that would allow me to trigger the inherited > method at each time the file containing the "sub-class" (e.g. Test2) is > loaded ? As Todd pointed out already, "inheritance" will happen only once, might it be that you have chosen a suboptimal mechanism ;) for what you want to achieve? Maybe you could tell us a little bit more about that? Cheers Robert -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck