> That's one way to do it.  Actually only a smaller change is needed
> because the root cause in this case is the scoping rule of the
> iteration variable in a "for" loop which is different than when
> iterating with a block as this example demonstrates:
> 

CORRECT :

>     names.each do |name|
>       define_method("m1_#{name}") do
>         puts "1_#{name}"
>       end
>     end

INCORRECT !


>     for name in names do
>       define_method("m2_#{name}") do
>         puts "2_#{name}"
>       end
>     end


Wow thanks Robert that was of help ...

So if i get this straight : what happens is that in the execution time 
as the for iterated over all the array until the end the variable that 
would be the one that gets printed out. If we use each to iterate over a 
block the scope of the name variable is saved and stays the same (it 
closes on itself) thus we get the correct name variable everytime.

Am i right !?

Regards
-- 
Posted via http://www.ruby-forum.com/.