From: "Hal E. Fulton" Date: 2002-04-21T13:22:32+09:00 Subject: Re: problem with alias ----- Original Message ----- From: "Guy N. Hurst" To: "ruby-talk ML" Sent: Saturday, April 20, 2002 4:12 PM Subject: problem with alias > I just discovered a problem with how alias works while > testing some code in irb. > > It is common in ruby to alias a method you are about to > override so you can still access the original functionality. > However, if that portion of code is executed more than > once (such as being included or evaluated more than once), > then the original method gets lost. > > In short, > > alias old_meth meth > alias old_meth meth > > will result in meth being lost forever. [snip example] That's interesting. I never thought of that. A workaround (if you see this happening) would be to check whether the target is defined first... if !defined? meth then alias oldmeth meth end Clunky, yes. And don't be tempted to use the modifier form: alias oldmeth meth if !defined? oldmeth It won't work. Think why. :) As for the send_original idea, I think that's not such a bad idea... would it be practical to make this one method "fixed in place" (can't be aliased, redefined, or removed?). That would fix the infinite regression problem and would not necessitate a new keyword. Just a thought. No doubt Matz has a better idea. Hal Fulton