如何在Ruby中使用條件運算符(?:)?條件運算符如何(? :)用于紅寶石?例如,這是對的嗎?<% question = question.size > 20 ? question.question.slice(0, 20)+"..." : question.question %>
3 回答

夢里花落0921
TA貢獻1772條經驗 獲得超6個贊
if_this_is_a_true_value ? then_the_result_is_this : else_it_is_this
if
if a then b else c end
=== a ? b : c
puts (if 1 then 2 else 3 end) # => 2puts 1 ? 2 : 3 # => 2x = if 1 then 2 else 3 endputs x # => 2
puts if 1
question = if question.size > 20 then question.slice(0, 20) + "..."else questionend

慕尼黑5688855
TA貢獻1848條經驗 獲得超2個贊
puts true ? "true" : "false" => "true" puts false ? "true" : "false" => "false"
- 3 回答
- 0 關注
- 549 瀏覽
添加回答
舉報
0/150
提交
取消