Reputation: 1395
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?
Upvotes: -1
Views: 3450
Reputation:
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.
Upvotes: 3