From: Ozgur Murat Homurlu Date: 2006-02-16T04:06:32+09:00 Subject: Re: [ ruby-Bugs-3565 ] Method object used as Object#instance_eval block doesn't work (as expected) On Pr�, 2006-02-16 at 03:18 +0900, Yukihiro Matsumoto wrote: > A method object is tightly bound to its receiver. Even instance_eval > cannot rebind the bound receiver of a method object, mostly because > methods simply just don't work well with objects of other types, > unlike simple Proc objects written in Ruby. For example, string > methods like #split expect their receiver to be strings, and no other > type. If rebound is allowed they would just crash. I see. This is the the answer I was expecting. I was just experimenting with the language to understand it better. > Considering above reason, we have three choices: a) disallow invoking > instance_eval with a proc made from a method at all. b) abandon > receiver rebinding for a proc made from a method. c) add type checks > for the receivers in every methods, no matter who implemented. these > checks could be source of bugs, and could slow down the interpreter a > lot. > > I'd rather choose option b. It's safe, fast, and inconsistency is > small. As far as I can imagine, not many people try to rebind the > receiver of the bound method using instance_eval(). I agree, option b would be the optimum solution. I believe, for consistency, additionally a warning might be generated and this limitation should be stated in instance_eval documentation, and maybe in Method#to_proc documentation too. Thank you, Regards.