How to include a condition inside a string in ruby

ruby, string

Solution

"This is the #{y.nil? ? x : y} question"

or

"This is the #{y ? y : x} question"

or

"This is the #{y || x} question"

you can use `y||x` inside interpolation just like outside it

Problem

I want to place a variable within a string, but also have a condition on the variable something like: ``` x = "best" "This is the #{if !y.nil? y else x} question" ``` outside the string I can do `y||x`. what do I do inside the string?

Original source