字符串我想將一個字符串中的變量中的條件,同時也對可變如何包括紅寶石
類似的情況:
x = "best"
"This is the #{if !y.nil? y else x} question"
字符串我可以在外面做y||x
。我在字符串內做什麼?
字符串我想將一個字符串中的變量中的條件,同時也對可變如何包括紅寶石
類似的情況:
x = "best"
"This is the #{if !y.nil? y else x} question"
字符串我可以在外面做y||x
。我在字符串內做什麼?
"This is the #{y.nil? ? x : y} question"
或
"This is the #{y ? y : x} question"
或
"This is the #{y || x} question"
可以使用y||x
內插值就像外面
您可以絕對做一個字符串中相同
y = nil
x = "best"
s = "This is the #{y || x} question"
s # => "This is the best question"
使用三元運算:
"This is the #{!y.nil? ? y : x} question"