Mike Austin schrieb:
> Since you bring this up, there are a few more cases where implicit 
> locals declaration causes unexpected behavior (if new to ruby that is):
> 
> x = 10
> (1..10).each { |i| x = x + i }  # x == 65
> x = 10
> (1..10).each { |i| x = i }  # x == 10
> 
> So if you're assigning x to itself in some way, it recognizes x in the 
> enclosing scope, else it creates a new local.  That's kind of a 
> confusing rule.    Also, what if I wanted the first example to create a 
> local?  How do I refer to the toplevel `x` in the second?

Mike, you're accessing the toplevel "x" in both cases:

   x = nil
   (1..10).each { |i| x = i }  # x == 10

Regards,
Pit