From: "David A. Black" Date: 2008-03-22T03:26:20+09:00 Subject: Re: dynamically defining a method on an instance that references vars in enclosing scope? Hi -- On Sat, 22 Mar 2008, mutahhir hayat wrote: > I get you, since the block passed to class_eval was defined in the > same scope as x, it would be knowledgeable about it. But tell me, > other than academic, won't this be really bad to use? Like, maybe you > shadow some variable, and so on... I dunno, :P as i said, nearing my > limit, so maybe i'm just jabbering here. But it was fun learning from > you, glad to be on this list. Thanks. One of the most important roles of code blocks is to serve as closures -- that is, functions that remember the context of their own creation. In Ruby 1.9, the rules of parameter assignment are changing somewhat, so that it's easier to avoid trampling outside variables; but you can still use those variables if that's your purpose. David -- Upcoming Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS, April 14-17 2008, New York City CORE RAILS, June 24-27 2008, London (Skills Matter) See http://www.rubypal.com for details. Berlin dates coming soon!