M
Michael Schuerig
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?
Michael
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?
Michael