Question

I'm doing Ruby the Hard Way (ex9) -> http://ruby.learncodethehardway.org/book/ex9.html

Why can it not find the constant PARAGRAPH?

ERROR =>:

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

CODE (my input):

# 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

NOTE: I modified the code in paragraph and stripped integers and possible statements like "if or "or" just to make sure I wasn't doing something else wrong. With the "right" code I get the following...

LESSON CODE ERROR =>:

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

LESSON CODE: (my input)

# 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
Was it helpful?

Solution 2

Like Some Guy said, assigning "Here are the days: ", days to puts is your problem. When you hit the line puts <<PARAGRAPH the interpreter attempts to append PARAGRAPH to the array puts instead of generating the here doc, but of course PARAGRAPH is undefined.

Its kind of interesting, (though not super helpful) to note that you could actually still force it to work with the syntax

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

OTHER TIPS

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

is your problem. The = is probably not desired.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top