如何在Ruby中创建段落?

时间:2011-11-23 08:43:58

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

我正在运行一个教程,即使我完全按照指示输入了这个代码,但它会返回语法错误。 任何人都可以解释如何在ruby中创建一个段落吗?

我的尝试如下所示。

由于

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

6 个答案:

答案 0 :(得分:3)

你有Puts。你想要puts

答案 1 :(得分:2)

将它设为method of module Kernel,您应该用小写字母写puts

答案 2 :(得分:1)

original tutorialputs,而不是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

答案 3 :(得分:0)

就像有些家伙所说,将"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

答案 4 :(得分:0)

有趣的是,你可以在这里做。你可以这样做:

<<PARAGRAPH
typing lines of data, etc
more input
PARAGRAPH
您选择的

或'任何'大写单词:

<<BUILDING
typing lines, etc
BUILDING

我用过的每一个字都有用。

答案 5 :(得分:0)

检查PARAGRAPH末尾是否有空格。确保在PARAGRAPH之后没有空间,你很高兴。

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