我剛開始學習Ruby,不確定是什麼導致錯誤。我正在使用紅寶石1.9.3Ruby將字符串和整數放在同一行
puts 'What is your favorite number?'
fav = gets
puts 'interesting though what about' + (fav.to_i + 1)
in `+': can't convert Fixnum into String (TypeError)
在我上一個puts語句中,我認爲它是一個字符串和計算的簡單組合。我仍然這樣做,但只是不明白爲什麼這不起作用
好吧,有點像字符串有字符串嗎?整數不能與字符串混合?感謝您的解決方案! – catchmikey
是的,有點:[這是一個很好的閱讀](http://www.rubyfleebie.com/ruby-is-dynamically-and-strongly-typed/)。 –