From: Gavin Sinclair Date: 2010-07-19T23:38:22+09:00 Subject: Re: Instance eval in 1.8 and 1.9 >> >> It seems like this could be a regression. > > Seconded. The program works OK for me with ruby 1.9.2dev (2009-07-18 > trunk 24186) [i686-linux] Data so far: * works on 1.9.1-p376 [Caleb, Gavin] * works on 1.9.2dev (2009-07-18) [Brian] * doesn't work on 1.9.2dev (2010-07-02) [Gavin] That agrees with Nobu's comment on ruby-core (which I should have relayed here earlier, sorry): No, it not the point. Now instance_eval yields the self. This code (to boil the problematic case down) fails... code = lambda { 42 } instance_eval &code ...because instance_eval passes 'self' as a parameter to the block. Lambdas are fussy about parameters being accounted for, hence the ArgumentError. Procs are not fussy about parameters, so replace 'lambda' with 'proc' in the above code and it works. For that matter, _this_ works too: code = lambda { |s| 42 } instance_eval &code From what I gather: * in 1.8.x, instance_eval passed self but it was an undocumented feature and lambdas weren't fussy so it didn't matter * in 1.9.1 instance_eval stopped passing self (don't know whether that change was intentional) * heading towards 1.9.2 it started passing self again, from about December 2009 For a (still?)-undocumented feature, the message "ArgumentError: 0 for 1" is not very helpful. Gavin