1

I want to embed or nest a Ruby expression inside string interpolation, and have it evaluated. Something like this, though this doesn't work:

"#{is_true? ? 'True' : #{false_for_x? ? 'False for X' : 'False for Y'}}"

Can I do this? If so, how?

1 Answer 1

1

String interpolation has no sense outside string literals; probably you want this:

"#{is_true? ? 'True' : "#{false_for_x? ? 'False for X' : 'False for Y'}"}"

Or this (better):

"#{is_true? ? 'True' : (false_for_x? ? 'False for X' : 'False for Y')}"
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.