繁体   English   中英

如何在Ruby中创建段落?

[英]How do I create a paragraph in Ruby?

我正在遍历一个教程,即使我完全按照指示键入了此代码,但又返回了语法错误。 谁能解释如何在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

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: ", daysputs是你的问题。 当您击入puts <<PARAGRAPH ,解释器会尝试将PARAGRAPH追加到数组puts而不是生成here doc,但是当然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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM