------ art_2283_26015307.1161833909150 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/26/06, dblack / wobblini.net <dblack / wobblini.net> wrote: > > Hi -- > > On Thu, 26 Oct 2006, Daniel N wrote: > > > My understanding of blocks is at best still very shakey, but is there a > > reason in all these that something like > > > > def tell > > yield self > > end > > > > would not have the desired effect. > > > > Then with appropriate method missings etc you could call whatever you > like > > in the block. If the drink and eat methods are already defined in the > > object, they would be called as appropriate. > > > > so to use it. > > > > obj oo.new > > obj.tell do > > eat 'burger', 'fries' > > drink 'beer' > > end > > > > Is there a reason that this would not have the same effect as the > > instance_eval methods? > > Yes: instance_eval temporarily changes "self", and that means that > bareword method calls like eat and drink will be directed to the Foo > object. Otherwise, it's just like doing: > > eat > > in the middle of a program where you haven't defined an eat method. I'm a bit lost with that. I think I don't understand what is self inside the block. In the case of def tell yield self end > obj oo.new > obj.tell do > eat 'burger', 'fries' > drink 'beer' > end What is self inside the block? ------ art_2283_26015307.1161833909150--