0

I am following Learn Ruby The Hard Way chapter 14. I typed it out myself what is on the tutorial. I even tried copying and pasting what is on the tutorial itself. My text file ex.rb has the following:

user = ARGV.first
prompt = '> '

puts "Hi #{user}, I'm the #{$0} script."
puts "I'd like to ask you a few questions."
puts "Do you like me #{user}?"
print prompt
likes = STDIN.gets.chomp()

puts "Where do you live #{user}?"
print prompt
lives = STDIN.gets.chomp()

puts "What kind of computer do you have?"
print prompt
computer = STDIN.gets.chomp()

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

The tutorial says I should get the following output:

$ ruby ex14.rb Zed
Hi Zed, I'm the ex/ex14.rb script.
I'd like to ask you a few questions.
Do you like me Zed?
> Yes
Where do you live Zed?
> America
What kind of computer do you have?
> Tandy
Alright, so you said Yes about liking me.
You live in America.  Not sure where that is.
And you have a Tandy computer.  Nice.

I am getting two errors. Here they are:

$ ruby ex.rb Zed
ex.rb:19: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '
('
Alright, so you said #{likes} about liking me.
               ^
ex.rb:20: syntax error, unexpected keyword_in, expecting end-of-input
You live in #{lives}. Not sure where that is.

Any ideas on what is going on?

sawa
  • 165,429
  • 45
  • 277
  • 381
user3408293
  • 1,377
  • 6
  • 18
  • 26
  • I've copied the code you have posted and it works fine, are you sure you haven't modified it since you got the error? – toro2k Apr 17 '14 at 13:08
  • Works for me as well. Those errors don't seem like they would be the result of anything wrong near line 19. I altered around line 19 but was never able to get those errors. – Stratus3D Apr 17 '14 at 13:13

1 Answers1

3

Taking the file from your question it works fine for me too.

However, when I changed puts <<MESSAGE to be:

puts << MESSAGE

i.e. with a space between << and MESSAGE I get exactly your error.

You must have some character in your file at that position that is missing when you copy/paste the file to here.