From: Logan Capaldo Date: 2007-09-09T12:39:20+09:00 Subject: Re: Bug in lambda? On 9/8/07, 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 Not a bug, it's a "feature". I don't like it either. foo = lambda { |$this_works_too| } foo.call(2) p $this_works_too class SoDoesThis attr_reader :foo def setter lambda { |@foo| } end end bar = SoDoesThis.new bar.setter["this is sparta"] p bar.foo