Joel VanderWerf wrote:
> There is a small bug in the text though:
> 
> x = 1
> {|x|  }
> 
> Maybe there should be an "x=3" in the block?

No, it's correct as it is. The point is that in ruby 1.8, |x| is 
assigned to each time the block is called, and if x existed before the 
block, it remains after the block as the last value. This is regardless 
of whether you actually use or assign to x inside the block.

$ irb
irb(main):001:0> x = 1
=> 1
irb(main):002:0> [2,3].each{|x| }
=> [2, 3]
irb(main):003:0> x
=> 3

But in ruby1.9, |x| is a local block argument, independent of any local 
variable x outside the block.

$ irb19
irb(main):001:0> x = 1
=> 1
irb(main):002:0> [2,3].each{|x| }
=> [2, 3]
irb(main):003:0> x
=> 1
-- 
Posted via http://www.ruby-forum.com/.