From: "David A. Black" Date: 2005-09-18T21:28:56+09:00 Subject: Re: Finding out if a method is already redefined Hi -- On Sun, 18 Sep 2005, Michael Schuerig wrote: > > My problem occurs in the context of Rails, but is really core Ruby. In > its "development environment" Rails uses load, not require, to load > files anew for each request. This is to enable changes to the running > application. I'm running into a problem with this mechanism when > redefining a method *and* referring to the old method in the redefined > one. When this redefinition happens twice, it results in an infinite > recursion. I've tried to guard the redefinition with a check for the > new method, but this doesn't work, the new alias is not recognized. > > unless method_defined?(:method_new) > alias_method :method_old, :method > def method_new(options = {}) > ... > method_old(options) > end > alias_method :method, :method_new > end > > What do I have to do to make this work? I can't duplicate your problem. Here's what I'm doing: # l.rb: class C def meth puts "old" end end c = C.new c.meth load 'load.rb' c.meth load 'load.rb' c.meth # load.rb class C unless method_defined?(:meth_new) alias_method :meth_old, :meth def meth_new puts "new" meth_old end alias_method :meth, :meth_new end end # output of running l.rb: old new old new old David -- David A. Black dblack@wobblini.net