Spot the difference
This does what you’d expect:
%w(msgtype state chstat chstatmsg qpstat qpstatmsg merchant merchantemail cardtype).each do |attr|
define_method(attr) do
params[attr]
end
end
This does not:
for attr in %w(msgtype state chstat chstatmsg qpstat qpstatmsg merchant merchantemail cardtype)
define_method(attr) do
params[attr]
end
end
The latter version uses the last value for attr (in this case, cardtype) for each method it defines.
I thought for x in y was just syntactilcal sugar. Apparently not. You live, you learn :)
About Calvin Correli
I've spent the last 17 years learning, growing, healing, and discovering who I truly am, so that I'm now living every day aligned with my life's purpose.
0 comments
Leave a comment