我正在浏览一个教程,即使我完全按照指示输入了这段代码,它还是会出现语法错误。谁能解释如何在 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
我正在浏览一个教程,即使我完全按照指示输入了这段代码,它还是会出现语法错误。谁能解释如何在 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
你有Puts
. 你想要puts
。
说它是模块 Kernel 的一个方法,你应该用小写字母写:puts
原始教程有puts
,而不是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
就像有人说的那样,分配"Here are the days: ", days
给puts
你是你的问题。当您点击 lineputs <<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
有趣的事情在这里你可以做。你可以这样做:
<<PARAGRAPH
typing lines of data, etc
more input
PARAGRAPH
或您选择的“任何”大写单词:
<<BUILDING
typing lines, etc
BUILDING
我使用的每一个词都有效。
检查 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