From: "Mauricio Fernández" Date: 2004-04-29T16:07:11+09:00 Subject: Re: alias or alias_method problem On Thu, Apr 29, 2004 at 01:18:38PM +0900, Jeff Mitchell wrote: > 99% of the time alias_method is used in conjunction with > redefining a method. The above issues would have been > avoided if ruby had something like, > > redef foo(*args) > puts "new foo" > previous(*args) # calls old foo > end batsman@tux-chan:/tmp$ cat redef.rb class Module def redef(meth, &block) prev = self.instance_method(meth) define_method(meth) do |*a| block.call prev.bind(self), *a end end end class A def foo(*a) puts "A#foo #{a.inspect}" end end a = A.new a.foo class A redef :foo do |prior, *a| puts "new foo" prior[*a] end end a.foo batsman@tux-chan:/tmp$ ruby redef.rb A#foo [] new foo A#foo [] More details in [ruby-talk:97440]. -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Those who don't understand Linux are doomed to reinvent it, poorly. -- unidentified source