From: Robert Klemme Date: 2013-03-21T19:47:04+09:00 Subject: Re: Finding one's way with 'super' in define_method/alias_emthod On Thu, Mar 21, 2013 at 11:31 AM, Marcin R. wrote: > Robert Klemme wrote in post #1102288: > >>> 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. > > Is there anything like compiled Ruby code? I'm curious. Could you > elaborate? AFAIK the Ruby code is parsed and compiled to some internal byte code representation. For more details you would have to use your favorite search engine or look at MRI source (and JRuby source and sources of the other Rubies). > Ok, I solved this. My description was rather clumsy, but code speaks > more than thousand words. I usually prefer a written explanation of the purpose of the code. The code is the solution but the goal does not always become apparent from looking at code. > This block gives user the ability to write method like > this: > > chain_method :hello > def hello > p "Hello" > yield > end Why would I want to do that? What is that supposed to do? > If call is recursive than it is either 'super' call or plain recursion, Super call is not recursion. Recursion is when a method invokes itself. Super calls are used to augment a super class's implementation of a method with additional logic specific to the derived class. > we don't care which one it is. In this case we're binding method > reference that is accessible from closure we're in to self and call it > via #call, thus bypassing polymorphic call that caused troubles in the > first place. Makes sense? I'll be happy to hear your take on this. I still don't understand what you are up to and what your ultimate goal is. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/