From: dblack@... Date: 2007-09-09T17:28:16+09:00 Subject: Re: Bug in lambda? Hi -- On Sun, 9 Sep 2007, kevin cline wrote: > This looks like a pretty serious bug. It seems that lambda- > expressions are not properly localizing their formal arguments: > > bash-3.2$ ruby --version > ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] > > bash-3.2$ cat lambda-bug.rb > a = 0 > f = lambda { |a| a } > puts "a = #{a}" > puts "f.call(1) => #{f.call(1)}" > puts "now a = #{a}" > > bash-3.2$ ruby lambda-bug.rb > a = 0 > f.call(1) => 1 > now a = 1 Definitely not a bug. Block parameters use assignment semantics, with regard to the scope in which the block appears. In your example, you're assigning 1 to a. If you create a local variable inside the block, however, it only exists for the duration of the block. As far as remember, Guy Decoux and I are the only two people who think that this makes perfect sense, once you learn it, and should not be changed :-) David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)