Hi everyone,

I was trying to define instance methods on a class based on an given array =
of strings. I run into different results using two different types of itera=
tion. I can't understand the resulting behaviour just in a case, the follow=
ing piece of code will be more meaningful than words:

class Toy
   =20
end

%w{e1 e2}.each { |m|
    Toy.class_eval do
        define_method m do
            puts m
        end
    end
}

for m in %w{u1 u2}
    Toy.class_eval do
        define_method m do
            puts m
        end
    end
end

p=3DToy.new

puts p.e1 # ok
puts p.e2 # ok
puts p.u1 # WTF
puts p.u2 # ok

I tested it with ruby 1.8.7 and with 1.9.2 and I get the same results . Obv=
iously, the third result is the only I don't understand :). It seems that d=
efine_method defers the evaluation of "m" object when used with a for.

I'm relatively new to Ruby and  maybe this is the expected behaviour. I wou=
ld like to understand the difference between the to version, thank you.

P.S. I added this example as a gist, you can read it here https://gist.gith=
ub.com/868310