From: Logan Capaldo Date: 2006-04-27T10:37:58+09:00 Subject: Re: Extending Methods On Apr 26, 2006, at 9:26 PM, Geoff Stanley wrote: > > I don't want to use inheritence and super because that would mean each > plugin would create its own child class of the base class it wants to > modify. This causes two problems: 1) The child classes wouldn't do > anything; They'd have to be hooked into the main program somehow... > troublesome and 2) The child classes wouldn't work together. If I have > two plugins modifying the same method in the same base class, they > both > need to be able to modify it, not one overruling the other. > Sound's like you need to make a more formal design to me then: class Plugin def initialize_delta(other_self) # Stuff that needs to be in the initialize of the plugin end end class NormalMainClass def self.add_plugin(plugin) @plugins ||= [] @plugins << plugin end def self.plugins @plugins ||= [] end def initialize # generic initialization here self.class.plugins.each do |plugin| instance_eval(&plugin.method(:initialize_delta)) end end end # main part of program # load plugins from files NormalMainClass.add_plugin(Plugin) obj = NormalMainClass.new Of course the way of outlined this may not be appropriate for what you want to do, but it should give you some ideas. Just because ruby _can_ do a lot of stuff auto-magically doesn't mean you have to, when it's not specific enough for you. (Note also this code is totally untested, I may have message something up).