2015-09-30 63 views
0

我目前正在與朋友一起練習14,這是一些非常簡單的字符串插值和用戶輸入抓取。我的代碼如下所示:「學習紅寶石硬的方法」缺少輸出的練習14

user_name = ARGV.first               
prompt = '> ' 

puts "Hi #{user_name}." 
puts "I'd like to ask you a few questions." 
puts "Do you like me #{user_name}? ", prompt 
likes = $stdin.gets.chomp 

puts = "Where do you live #{user_name}? ", prompt 
lives = $stdin.gets.chomp 

puts "What kind of computer do you have? ", prompt 
computer = $stdin.gets.chomp 

puts """ 
Alright, so you said #{likes} about liking me. 
You live in #{lives}. Not sure where that is. 
And you have a #{computer} computer. Nice. 
""" 

應工作非常簡單,但什麼我的發現是likes=行後,下一行提示「你住在哪裏」是不是在屏幕上顯示,但提示lives=。也就是說,在進入「喜歡」之後,立即跳轉到「行」提示,而不顯示以前的提示輸出!從computer=開始的下一個提示按預期工作。

我使用Ruby 2.1.2,但出現在2.2.3相同的行爲,以及在線REPL here

爲什麼會出現這種情況?

+1

三重引號是Python的東西。一個'''在Ruby中已經足夠了 – steenslag

+0

這是一本書的直接引用 –

回答

2

在投放第8行後,您有=。刪除它應該可以解決問題。

+0

*嘆氣* - 這是小事情,我在幫助我的朋友時忽略了這一點。 –