From: Jean-Hugues ROBERT Date: 2004-05-03T20:29:12+09:00 Subject: Re: Why no Proc##[]=() ? Why no Proc##replace() ? Thanks. I guess I need to : while not done_xxx begin x = nil p = lambda { x ||= long_method } end ... using begin/end to make sure that *each* proc has its own x EOM Jean-Hugues At 14:39 03/05/2004 +0900, you wrote: >Local variables work, but they have to be defined outside of the scope of the >block: > > x = nil > p = lambda { x ||= long_method } > > p.call > p.call > >This only calls long_method once, at least on my version of Ruby (1.8.1). > >Apparently, without the preceding "x = nil" x goes back to being undefined >when the block closes, so changes to it aren't persistant. If it's defined >outside the scope of the block, though, those changes stay. > >Maybe this will change when locals leak out of block scoping. Currently if >you want x to be accessible after the block, you need the preceding x = nil. >But in 2.0 it's changing so that you won't, so maybe you won't need it in >this case either. > >- Dan ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17