2

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?

1 Answer 1

3

Use the Object#send method:

win_streak = u.send("#{n}_win_streak")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.