shfury
shfury

Reputation: 389

How do I create a paragraph in Ruby?

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

Upvotes: 1

Views: 2047

Answers (6)

sanjeet kumar
sanjeet kumar

Reputation: 1

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

Upvotes: 0

sidonstackoverflow
sidonstackoverflow

Reputation: 69

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

Upvotes: 0

rrmode
rrmode

Reputation: 1

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.

Upvotes: 0

Andrew Grimm
Andrew Grimm

Reputation: 81631

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

Upvotes: 1

WarHog
WarHog

Reputation: 8710

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

Upvotes: 2

Carl Zulauf
Carl Zulauf

Reputation: 39568

You have Puts. You want puts.

Upvotes: 3

Related Questions