我正在关注学习Ruby The Hard Way第14章。我自己输入了本教程的内容。我甚至尝试复制和粘贴教程本身的内容。我的文本文件ex.rb具有以下内容:
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
教程说我应该得到以下输出:
$ 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.
我收到两个错误。他们在这里:
$ 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.
有关正在发生的事情的任何想法?
答案 0 :(得分:2)
从您的问题中提取文件也适用于我。
但是,当我将puts <<MESSAGE
更改为:
puts << MESSAGE
即。在&lt;&lt;&lt;&lt;&lt;和消息我得到了你的错误。
当您将文件复制/粘贴到此处时,您的文件中必须有一些字符丢失。