ts <decoux / moulon.inra.fr> writes:

> >>>>> "D" == Dave Thomas <Dave / PragmaticProgrammer.com> writes:
> 
> D>   n = 123
> D>   3.times {{
> D>     puts n
> D>     n += 2
> D>   }}
> 
>  What do you expect with
> 
>    a = [1]
>    3.times {{
>       a << 2
>    }}
>    p a

[1,2,2,2], the same as if you passed 'a' in to a method

   def x(a)
    a << 2
   end

   a = [1]
   x a
   x a
   x a
   p a          #=> [1,2,2,2]

If you wanted to avoid object aliasing, you could eliminate the
convenience that variables in a block are initialized to their
outer-scope counterparts, and instead force people to pass them in as
parameters to the block. However, I'd say that the Ruby way would
favor convenience over such purity :)



Regards


Dave