On 3/22/06, Mohammad Khan <mkhan / lextranet.com> wrote:
> mkhan@mkhan:~$ irb
> irb(main):001:0> batman = 'robin'
> => "robin"
> irb(main):002:0> [ 'cat', 'dog', 'horse', 'chicken' ].each { |batman|
> puts batman }
> cat
> dog
> horse
> chicken
> => ["cat", "dog", "horse", "chicken"]
> irb(main):003:0> puts "Now you might think this would say 'robin', but
> it says: #{batman}"
> Now you might think this would say 'robin', but it says: chicken
> => nil

It's true that blocks introduce a new scope.
However, if they use variables that are in scope outside the block,
they don't shadow those variables, they use them.

--
R. Mark Volkmann
Object Computing, Inc.