F
F. Senault
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 :
load "test.rb"
load "test.rb"
class Test
def self.inherited(c)
puts "#{c} inherited Test !"
end
end
load "test2.rb"
puts "In #{__FILE__}."
class Test2 < Test ; end
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 ?
(The real plugin class, if there is a need, is here :
http://www.lacave.net/~fred/projets/plugin.rb )
Fred
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 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]ruby -v
#! /usr/local/bin/rubycat first.rb
load "test.rb"
load "test.rb"
#! /usr/local/bin/rubycat test.rb
class Test
def self.inherited(c)
puts "#{c} inherited Test !"
end
end
load "test2.rb"
#! /usr/local/bin/rubycat test2.rb
puts "In #{__FILE__}."
class Test2 < Test ; end
In ./test2.rb.ruby first.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 ?
(The real plugin class, if there is a need, is here :
http://www.lacave.net/~fred/projets/plugin.rb )
Fred