From: Robert Klemme Date: 2013-03-19T23:32:13+09:00 Subject: Re: Finding one's way with 'super' in define_method/alias_emthod On Tue, Mar 19, 2013 at 2:46 PM, Marcin R. wrote: > Robert Klemme wrote in post #1102170: >> On Mon, Mar 18, 2013 at 8:39 PM, Marcin R. wrote: >>> Robert Klemme wrote in post #1102151: >>>> On Mon, Mar 18, 2013 at 5:50 PM, Marcin Rzeźnicki > > Sorry for late answer, busy day at work. No problem at all. After all, you were the one looking for a solution. :-) >> 1. Could be viewed as an aesthetic issue: the behavior of code would >> change after the definition of the method. > > Yes, well, it's not that I want whole Ruby to be changed because of my > whining. I guess what I was trying to ask was if there is some obvious > solution that I overlooked (you know, kind of: "Geez, yet another rookie > having problems with 'super'. Listen man, do yourself a favor and do it > like this and this, it's been solved 1000 times before") I'm not aware of any right now. >> 2. As a consequence of changed behavior there would be a runtime >> effect: while executing the interpreter would have to have knowledge >> of the name used to invoke a method. Now you could argue that this >> knowledge does actually exist (caller provides it) but it may incur a >> runtime hit - for just a small amount of use cases. > > I don't think so, I mean, obviously super already has to know the name > of the method it's invoked from to do a lookup. Yes, but with the current solution the name can be baked into the compiled version of the Ruby code. While with your suggestion the name would have to be retrieved for every single call. That is the difference. > The question is - where the name is taken from. Exactly. > If method used its "actual" name instead of > "original" name then we're fine with super itself. An additional cost I > can see lurking here is that define/alias method would need to copy a > method instance (if called with one as an argument) and change its name > to reflect aliasing, rather than just reference the original one. > Anyhow, this is purely hypothetical. Yes, that might be a solution. > BTW, having given it a little thought I think that I can easily check > for the condition of being called from super myself. What it takes is > just a flag that signals that we're recursively called and a check what > real 'self' is. I still need to flesh out the details but I guess this > might work. Good. I don't understand why "self" might change when chaining method calls on the same instance but I truest you to sort that out. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/