From: 7stud -- Date: 2007-09-09T20:39:19+09:00 Subject: Re: Bug in lambda? 7stud -- wrote: > The behavior in question seems consistent with the way closures work in > Ruby: > > def func(x) > y = 10 > lambda {puts x+y; y += 1} > end > > p = func(5) > p.call > p.call > p.call > > --output:-- > 15 > 16 > 17 > > Is there something inconsistent with the way a block defined outside of > any functions behaves versus a closure? I guess this would be a more complete example: $z = 100 def func(x) y = 10 lambda { puts x+y+$z x+=1 y += 1 $z+=100 } end p = func(5) p.call p.call p.call --output:-- 115 217 319 -- Posted via http://www.ruby-forum.com/.