Caleb Clausen
7/27/2006 6:07:00 PM
On 7/27/06, Pedro Côrte-Real <pedro@pedrocr.net> wrote:
> On 7/27/06, Caleb Clausen <vikkous@gmail.com> wrote:
> > At a guess, (something is) rcov is also wrapping #get and using the
> > same name for the old version of the method. At least, that's always
> > been the explanation when I've encountered these 'wrapping a method
> > causes infinite recursion' problems. Try this way instead, it should
> > eliminate any possibility that your code is participating in the
> > recursion.
>
> I tried a different name and it didn't work so I don't know what's
> actually happening. But I'd like to know. Anyone?
That's odd, considering that the define_method trick seems to be
working for you. As I said, my diagnosis was just a guess.
> > old_get=instance_method(:get)
> > define_method(:get) do |*args|
> > old_get[*args]
>
> I had to replace this line with:
>
> old_get.bind(self).call(*args)
Ooops! My apologies for posting broken code. Looks like you got the
idea, anyway.
> Thanks for this solution. It's working again now. This probably means
> that there should be an alias_method equivalent to do this. I didn't
> really want to change the method name, I wanted to replace it with
> something that could still call the old behavior. 0-step inheritance
> so to speak.
Wrapping methods seems to be pretty common in ruby. FYI the
define_method trick won't be able to wrap methods that take a block
until ruby 1.9.
> > This trick was originated by Mauricio Fernandez, as far as I know.
>
> Thanks to him too then,
Just a BTW, he's the same guy that wrote rcov. So now you have 2
things to thank him for.