0

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

2 つのエラーが発生しています。どうぞ:

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

何が起こっているかについてのアイデアはありますか?

4

1 に答える 1

3

あなたの質問からファイルを取得すると、私にとってもうまくいきます。

ただし、次のように変更puts <<MESSAGEした場合:

puts << MESSAGE

つまり、 << と MESSAGE の間にスペースがあると、正確にエラーが発生します。

ファイルをここにコピー/貼り付けするときに欠落している文字が、ファイル内のその位置にある必要があります。

于 2014-04-17T13:25:50.467 に答える