Robert Klemme wrote in post #1102151:
> On Mon, Mar 18, 2013 at 5:50 PM, Marcin Rzenicki
> <marcin.rzeznicki / gmail.com> wrote:
>> Hi all!
>> This is my first post here, so please don't yell at me too harshly :-)>
> Welcome to the wonderful world of Ruby!
>

Thank you :-)

>>
>> So, as you can see 'super' is bound, perhaps a little unexpectedly, to>> a method instance rather than to its call site.
>
> Hmm, I'd still say it's the call site since the call site sits in
> method D#greeting even though the method is also known as D#curse.
>

Yes, maybe I picked wrong terminology in my example. What I meant was that even though this method object is still the same, it is being called as something different (I'd say - method instance is simply reused but that's an implementation detail for me, so I'd prefer it to be masked out), so I would expect call frames to represent that.

>> You can see it clearly
>> when inspecting the caller - in both cases it is 'greetings'. While
>> this may seem logical and sound, it is quite troubling when you try to>> make a wrapper method around user-defined method doing metaprogramming>> tricks.
>
>> Do you know any workaround? How can I overcome this problem and let
>> super be bound correctly if used from aliased method? Thanks in
>> advance for your opinions.
>
> I am not sure what you expect should be called "bound correctly".
> Basically what you did is you said D#curse should be D#greeting
> (either via define_method as shown above or alias).  That means, D's
> method #curse behaves like D's #greeting and hence ultimately invokes
> C#greeting and not C#curse.
>

When I imagine hypothetical pseudo-code implementation of define_method I'd rather see: object[:method_name] = method_instance.code, than object[:method_name] = method_instance :-)

> Btw, somehow your chain example seems incomplete: is #chain a method
> defined in Module?  What about method names?  I would have expected
> the chained method name to be given as argument.
>

Ah yes, I omitted lots of details for brevity, trying to get to the bottom line, if you will. Basically, chain is called from method_added hook. When you include the module it installs this hook, adds class method to specify the name of a "chained" method, listens for subclassing to get into child class to do the trick again etc., but I felt that this boilerplate was irrelevant to my problem.

> I once coded something together for wrapping methods - you may find it
> in the archives.  I am not sure though that I still have the code
> elsewhere...  I only found this one:
> https://gist.github.com/rklemme/3002732 but that's not the one I mean.
>

I will certainly try to find it. Many thanks. BTW, judging from example you posted (I have not yet run it, though) it exhibits the same problem as my implementation - calling super from #_m would call #m in parent class which could call #_m in child again.

--
Greetings
Marcin Rzenicki