Michael Schuerig
2005-Sep-17 18:00 UTC
Reloading and redefining methods: infinite recursion
When I redefine a method like this
class Klass
alias_method :method_without_addition, :method
def method_with_addition
...
method_without_addition
...
end
alias_method :method, :method_with_addition
end
I get into trouble in the development environment. As these definitions
are executed again for each request, the second time around
method_without_addition is actually the same as method_with_addition
and when called dies in an infinite recursion stack overflow.
I though something like this would help, but apparently it does not
class Klass
unless method_defined?(:method_with_addition)
alias_method :method_without_addition, :method
def method_with_addition
...
method_without_addition
...
end
alias_method :method, :method_with_addition
end
end
It gives a stack overflow just the same. How do I make this work?
Michael
--
Michael Schuerig The Fifth Rider of the Apocalypse
mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org is a programmer.
http://www.schuerig.de/michael/
