0
一個簡單的問題,但無法弄清楚如何解決它,在Ruby語言缺乏知識:紅寶石輸入輸出問題
class Game def initialize get_command end def get_command command = gets puts command # => POSITION puts command != "POSITION" # => true if command != "POSITION" command = get_command else return true end end end a = Game.new
每當我運行一個應用程序,並鍵入POSITION
它總是得到true
比較"POSITION"
任何人都可以解釋爲什麼?
謝謝
總是一個好主意來消毒用戶輸入 - 尤其是因爲不同平臺上的行尾字符不同 –