Reputation: 17502
I want to do this:
for u in users
['four', 'five', 'six', 'seven', 'eight'].each do |n|
win_streak = u."#{n}_win_streak"
end
end
But am get this: syntax error, unexpected tSTRING_BEG.
What is the proper syntax?
Upvotes: 2
Views: 75
Reputation: 139830
Use the Object#send
method:
win_streak = u.send("#{n}_win_streak")
Upvotes: 3