1

我正在浏览一个教程,即使我完全按照指示输入了这段代码,它还是会出现语法错误。谁能解释如何在 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
4

6 回答 6

3

你有Puts. 你想要puts

于 2011-11-23T08:48:07.880 回答
2

说它是模块 Kernel 的一个方法,你应该用小写字母写:puts

于 2011-11-23T08:49:16.723 回答
1

原始教程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
于 2011-11-23T22:21:58.350 回答
0

就像有人说的那样,分配"Here are the days: ", daysputs你是你的问题。当您点击 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
于 2013-10-30T12:30:34.297 回答
0

有趣的事情在这里你可以做。你可以这样做:

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

或您选择的“任何”大写单词:

<<BUILDING
typing lines, etc
BUILDING

我使用的每一个词都有效。

于 2015-03-19T03:06:59.493 回答
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
于 2015-08-27T20:10:16.187 回答