Вопрос

I am running through a tutorial and even though I have typed this code exactly as instructed it is coming back with a syntax error. Can anyone explain how to create a paragraph in ruby?

My attempt is shown below.

Thanks

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
Это было полезно?

Решение

You have Puts. You want puts.

Другие советы

puts it's a method of module Kernel, you should write it with small letter: puts

The original tutorial had puts, not Puts:

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

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\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

Interesting thing here you can do here. You could do:

<<PARAGRAPH
typing lines of data, etc
more input
PARAGRAPH

or 'any' capitalized word you choose:

<<BUILDING
typing lines, etc
BUILDING

Every word I have used works.

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.

It's 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

Check if you have blank space at the end of PARAGRAPH. Make sure there is no space after PARAGRAPH and you are good to go.

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top