Brian Candler <B.Candler / pobox.com> wrote in message > > 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 understand the problem now - its just that I have never found it to be a problem. When I first encountered Ruby a few years back, the thing that I had most trouble with was the assignment by reference. A couple of bad experiences in the early days persuaded me to be very careful about when I duplicated objects. And ensuring the block-locality of variables was one of those places. Personally, I tend to use a Struct to hold all the variables that I want to be block local (unless a Class is really needed). So what is the problem with something along the lines of Block_local=Struct.new("Block_local", :a, :b) a=1 b=2 [1,2,3].each do |x| local=Block_local.new(a,b) local.a*=x local.b+=x p local end p a,b bantham> ./local.rb #<Struct::Block_local a=1, b=3> #<Struct::Block_local a=2, b=4> #<Struct::Block_local a=3, b=5> 1 2 Or am I still missing the point somewhere? Best regards, Steve