rubylearn-ruby-the-hard-way

"Learn ruby the hard way" missing puts output on exercise 14


I'm currently working on exercise 14 with a friend, which is some really simple string interpolation and user input grabbing. My code looks like this:

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.
"""

Should work pretty simply, but what I'm finding is that after the likes= line, the next line prompting for "where do you live" is not displayed on the screen, yet the lives= is prompted for. That is, immediately after entering the "likes", the "lines" prompt is jumped to without showing me the prompt output from before! The next prompt starting at computer= works as expected.

I'm using ruby 2.1.2, but the same behavior appears on 2.2.3, and an online REPL here

Why does this happen?


Solution

  • You have an = after the puts on line 8. Removing it should fix the issue.