Ruby(HardWay(ex9))<<未初始化的常数PARAGRAPH

时间:2013-10-24 18:39:21

标签: ruby learn-ruby-the-hard-way

我正在努力做Ruby(ex9) - > http://ruby.learncodethehardway.org/book/ex9.html

为什么找不到常数PARAGRAPH?

错误=>:

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

CODE(我的意见):

# 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

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

课程代码错误=&gt;:

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

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

就像有些家伙所说,将"Here are the days: ", days分配给puts是你的问题。当您点击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