我有一個輸出學生數的三元運算符。nilclass未定義的方法'中心'
@students.count < 2 ? puts("Now we have #{@students.count} student").center(75) : puts("Now we have #{@students.count} students").center(75)
我不得不把在賣出期權後括號中的字符串,否則便想出爲錯誤:我的代碼
syntax error, unexpected ':', expecting end-of-input
但是,因爲我已經更新到本我的方法.center
不工作並且我收到此錯誤:
`input_students': undefined method `center' for nil:NilClass (NoMethodError)
如何使用括號解決此問題?
不要在這裏使用三元,使用'if'。另外,你正在'puts'中應用'center'。將它應用到字符串。 –
我有一個if語句,但我想重構。 – Benjamints
你認爲現在好多了嗎? –