On 10/14/07, SpringFlowers AutumnMoon <summercoolness / gmail.com> wrote:
> Pat Maddox wrote:
> > This seems to me along the same lines as
> >
> > a = 1
> > if true
> >   a = 10
> > end
> > p a  # => 10
> >
> > Which certainly is not surprising or unwelcome.
>
> when compared to the following it is surprising:
>
> a = 1
> p a
>
> def foo(a)
>   p a
> end
>
> for i in 1..10
>   foo(i)
> end
>
> p a
>
> ------------------
>
> E:\>ruby test_iterator2.rb
> 1
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 1

Well, that's kind of the point of blocks, isn't it?  They close over
any vars that are currently in scope.  Methods on the other hand have
their own scope.  I guess it could be confusing if you thought methods
and blocks were the same thing...but, um, they're not.

Pat