0

我正在做 Ruby the Hard Way (ex9) -> http://ruby.learncodethehardway.org/book/ex9.html

为什么找不到常量 PARAGRAPH?

错误=>:

$ ruby ex9.rb
ex9.rb:9: uninitialized constant PARAGRAPH (NameError)

代码(我的输入):

# Here's some new strange stuff, remember type it exactly.

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\n\Feb\nMar\nApr\nMay\nJun\nJul\nAug"

puts = "Here are the days: ", days
puts = "Here are the months: ", months

puts <<PARAGRAPH
Theres something going on here.
With the paragraph thing.
Well be able to type as much as we like.
Even four lines.
PARAGRAPH

注意:我修改了段落中的代码并删除了整数和可能的语句,例如“如果或”或“只是为了确保我没有做错其他事情。使用“正确”代码,我得到以下...

课程代码错误=>:

ex9.rb:12: syntax error, unexpected tIDENTIFIER, expecting $end
We'll be able to type as much as we like.
     ^

课程代码:(我的输入)

# Here's some new strange stuff, remember type it exactly.

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\n\Feb\nMar\nApr\nMay\nJun\nJul\nAug"

puts = "Here are the days: ", days
puts = "Here are the months: ", months

puts <<PARAGRAPH
There's something going on here.
With the PARAGRAPH thing
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
PARAGRAPH
4

2 回答 2

2
puts = "Here are the days: ", days
puts = "Here are the months: ", months

是你的问题。= 可能是不需要的。

于 2013-10-24T18:44:04.323 回答
1

就像有人说的那样,分配"Here are the days: ", daysputs你是你的问题。当您点击该行时puts <<PARAGRAPH,解释器会尝试附加PARAGRAPH到数组puts而不是生成此处的文档,但当然PARAGRAPH是未定义的。

它有点有趣,(虽然不是很有帮助)注意到你实际上仍然可以强制它使用语法

puts(<<PARAGRAPH)
Theres something going on here.
With the paragraph thing.
Well be able to type as much as we like.
Even four lines.
PARAGRAPH
于 2013-10-24T18:50:10.457 回答