From: apeiros Date: 2009-06-17T05:47:26+09:00 Subject: [ruby-core:23879] Re: instance_eval no longer yielding self in ruby 1.9 Am 16.06.2009 um 22:12 schrieb Yusuke ENDOH: > Hi, > > 2009/6/14 apeiros : >> Hi folks >> >> In ruby 1.8, instance_eval yielded self, this is no longer the case >> in ruby >> 1.9. >> Was this an informed decision or just an oversight (after all it was >> undocumented in 1.8)? >> If it was an informed decision I'd be interested in the rationale. > > matz's decision. [ruby-core:7365] Ah, interesting, thank you. > The rationale seems to be arguable... Indeed :) >> It was nice for blocks that didn't care whether they were >> instance_eval'd or >> just called/yielded to, as long as they get an argument. With 1.9 >> those >> blocks have to be written specifically for instance_eval and use self >> instead of the argument. > > You can use Object#instance_exec for the purpose. So I define the method conditionally like: if method_defined? :instance_exec then def ...; instance_exec(self, &block); ...; end else def ...; instance_eval(&block); ...; end end ? I don't know, but I find that solution somewhat ugly. The alternative is to have no 1.8 compatibility which is right now not too nice. Regards Stefan Rusterholz