From: "H.Yamamoto" Date: 2006-02-15T19:05:03+09:00 Subject: Re: [ ruby-Bugs-3565 ] Method object used as Object#instance_eval block doesn't work (as expected) >Hi, > >In message "Re: [ ruby-Bugs-3565 ] Method object used as Object#instance_eval block doesn't work (as expected)" > on Wed, 15 Feb 2006 09:44:58 +0900, noreply@rubyforge.org writes: > >|It seems like, unexpectedly introduced argument is the object "a". >|Also, "a.instance_eval" doesn't work, self is still instance of "W". > >The code says the receiver was passed as an argument by intention, but >I don't remember the reason at all, so that I would remove this >argument. If anyone meets any problem, tell me to revert. > Fowarding.... (Ozgur Murat Homurlu) http://rubyforge.org/tracker/index.php?func=detail&aid=3565&group_id=426&atid=1698 Hello, Removing the argument which contains the receiver solves only part of the problem. The other part is instance_eval doesn't set the self to the receiver. What the code tries to do is running W#foo in the context of a (that is, in W#foo, self should be equal to a). I know there are other techniques for this purpose but since Method objects can be converted to Proc objects and instance_eval runs Proc object given as a block in the context of the receiver (that is, self set to the receiver of instance_eval for the Proc), it's expected to be possible. Maybe the reason of passing receiver of instance_eval was taking this argument and setting self to it during the execution of method, because instance_eval definition requires this. Regards.