From: Yehuda Katz Date: 2009-01-19T02:23:32+09:00 Subject: [ruby-core:21409] Re: Proposal: Module#copy_method --000e0cd2984c7118920460c5156f Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit The code I posted above is a replacement for Rails' alias_method_chain that retains the original method name and allows the use of super instead of calling the old method via foo_without_bar. Eero is correct that copying methods the way Pit Captain suggested will not work unless me <= self. However, that restriction doesn't seem like it's actually required (unless I'm missing something), so maybe extend define_method to work like copy_method above is the way to go. -- Yehuda On Sun, Jan 18, 2009 at 8:23 AM, Eero Saynatkari wrote: > Excerpts from Pit Capitain's message of Sun Jan 18 11:23:48 +0200 2009: > > 2009/1/18 Yehuda Katz : > > > I'd like it to be possible to copy methods from one module to another. > (...) > > > > Note that on 1.8 you can simply change the line > > > > copy_method me, name > > > > to > > > > define_method(name, me.instance_method(name)) > > > > and it works without #copy_method. > > Only if me <= self, though? One can work around that > by using Method#to_proc, but it has its own problems. > > I am still not entirely sure of the use case, but I > take Yehuda at his word that he actually uses "foo" > in real code ;) > > > -- > Magic is insufficiently advanced technology. > > -- Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 --000e0cd2984c7118920460c5156f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable The code I posted above is a replacement for Rails' alias_method_chain = that retains the original method name and allows the use of super instead o= f calling the old method via foo_without_bar.

Eero is co= rrect that copying methods the way Pit Captain suggested will not work unle= ss me <=3D self. However, that restriction doesn't seem like it'= s actually required (unless I'm missing something), so maybe extend def= ine_method to work like copy_method above is the way to go.

-- Yehuda

On Sun, Jan= 18, 2009 at 8:23 AM, Eero Saynatkari <ruby-ml@kittensoft.org> wrote:
=
Excerpts from Pit Capitain's message of Sun Jan 18 11:23:48 +0200 2009:=
> 2009/1/18 Yehuda Katz <wycats@gmail.com>:
> > I'd like it to be possible to copy methods from one module to= another. (...)
>
> Note that on 1.8 you can simply change the line
>
>   copy_method me, name
>
> to
>
>   define_method(name, me.instance_method(name))
>
> and it works without #copy_method.

Only if me <=3D self, though? One can work around that
by using Method#to_proc, but it has its own problems.

I am still not entirely sure of the use case, but I
take Yehuda at his word that he actually uses "foo"
in real code ;)


--
Magic is insufficiently advanced technology.




--
Yehuda Katz=
Developer | Engine Yard
(ph) 718.877.1325
--000e0cd2984c7118920460c5156f--