Creating independent lambdas in loops

Because in the second case multi is local to the (do-end)
block. So each iteration has its own multi.

There is no block if you use for, so the multi in lambda
is the same for all iterartions.

This is tricky stuff...

cheers

Simon

···

-----Original Message-----
From: itsme213 [mailto:itsme213@hotmail.com]
Sent: Wednesday, September 28, 2005 3:02 PM
To: ruby-talk ML
Subject: Re: creating independent lambdas in loops

"ts" <decoux@moulon.inra.fr> wrote in message
news:200509281241.j8SCflhq021177@moulon.inra.fr...

>
> > a =
>
> > for multi in [2, 3, 4, 5]
> > a << lambda do |n|
> > n * multi
> > end
> > end
>
> [2, 3, 4, 5].each do |multi|
> a << lambda do |n|
> n * multi
> end
> end

Why the difference in behavior between these two?