鍍金池/ 問答/Ruby/ Ruby小白問題: 三目運(yùn)算符問題

Ruby小白問題: 三目運(yùn)算符問題

age = 27
word = "age = #{age}"
if age > 20 ? puts(word) : "no , no"

代碼如上,我想做的事情,很明顯,一個(gè)簡單的條件判斷執(zhí)行。
但是運(yùn)行出現(xiàn)錯誤,

./start.rb:171: syntax error, unexpected end-of-input, expecting keyword_then or ';' or 'n'
0 ? puts(word) : "Oh ,no , no"

怎么解決?加一點(diǎn)說明解釋,更好啦,

回答
編輯回答
礙你眼

if then end 這幾個(gè)都要有,只寫if是語法錯誤

2017年10月30日 15:09