Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
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')}"
Add a comment
Required, but never shown
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.
Explore related questions
See similar questions with these tags.