On Mon, Feb 17, 2003 at 08:24:48PM +0900, Steve Hill wrote:
> Could somebody please explain why anyone would write code like
> 
> a=1
> [1..3].each {|a| #do something }
> 
> and then be surprised about side effects. It just seems like asking
> for trouble to me.
> 
> Honestly, I'm not trolling or trying to dis anyone. I just *don't*
> understand!

That's not entirely the problem. It's also when your '#do something'
includes an assignment to 'b'. The behaviour then depends on whether 'b' was
assigned to outside the block or not. This is a bit of a battle for
newcomers, to discover that what is the simplest concept in most other
languages (variables) is actually one of the most complicated in Ruby.

I generated quite a lot of noise on this list while trying to understand
which, for which I apologise!

There is a Wiki on this topic now at
http://www.rubygarden.org/ruby?LocalVariablesAndBlocks

and please feel free to contribute ideas there. There have been postings in
the past arguing to keep things unchanged, and those opinions aren't really
represented there yet.

Regards,

Brian.