From: kjana@...4lab.to (YANAGAWA Kazuhisa) Date: 2003-01-30T20:42:43+09:00 Subject: Re: Local variables & blocks In message <1043862597.721507.16449.nullmailer@picachu.netlab.jp> matz@ruby-lang.org writes: > So that x in > > a.each do |item| > x = ... > end > p x > > would not be a block local variable. The code above will work without > preceding "nil" assignment. So in the following: # until here, there's no foo. 10.times do Thread.new do # long, time-varying process without foo. foo = Foo.new # process using foo. end end Do all new threads (and of course the main thread) share variable foo and their accesses are interleaved arbitrary? Well in that case we still use block parameter as block local variable but that's little quirky. # Modifying syntax a little and making block parameter can have # default value? such as `Thread.new {|foo = Foo.new| ...}' I heard once that that is one of current behavior --- a variable appears first in a block, that variable is localized for the block. -- kjana@dm4lab.to January 30, 2003 A man is known by the company he keeps.