calvin-brand-light-mode
calvin-brand-dark-mode
∕
⌘K
About Calvin Podcast We Can Do This Book Speaking
aAbout Calvin
Podcast
wWe Can Do This Book
sSpeaking
Back

Spot the difference

Other
Calvin Correli·Nov 5, 2008· 1 minute

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 :)

Previous [dk] Tjener du for lidt på dine kunder?
Next Video blogging is hard work

Comments

Write a comment...
00:00 Recording...
calvin-brand-light-mode
calvin-brand-dark-mode
1 Chestnut Hill Plaza #1139
Newark, DE 19713
United States
Copyright © 2026 Calvin Correli
powered by