From: gabriele renzi Date: 2003-11-17T11:31:11+09:00 Subject: Re: Local Variable Scope in Ruby2 il Mon, 17 Nov 2003 03:08:26 +0900, "Gavri Savio Fernandez" ha scritto:: >Hi, >I was going through matz's slides from the Ruby Conference 2003, and was checking out what the slides claimed was the most regrettable behaviour in ruby, namely that in the following code, > >def foo > a = nil > ary.each do |b| > c = b > a = b > end >end > > >b and c are local to the each-block while the variable a which is referred to in the block is not. i assumed that in Ruby2, 'a' too would be local to the block and there would be different way to refer to the variable a which is outside the block's scope. the point is that you don't need to explicitly use a declaration of a variable outside of the scope of the block. If you want to use block local variables you would just need to do: ary.each do |normal_var,block_local_var_initialized_to_nil | use the vars end BTW probably you need block local vars rarely (apart from those declared in the || )