<< DESC在红宝石中意味着什么?

Fir*_*zis 2 ruby heredoc

我正在学习Ruby,在我使用的书中,有一个这样的示例代码

#...
restaurant = Restaurant.new
restaurant.name = "Mediterrano"

restaurant.description = <<DESC
One of the best Italian restaurants in the Kings Cross area, 
Mediterraneo will never leave you disappointed
DESC

#...
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释一下<< DESC在上面的例子中意味着什么吗?它与常见的字符串双引号有何不同?

chr*_*ais 10

它用于创建多行字符串.基本上,''DESC'告诉ruby在下一个'DESC'关键字之前考虑所有内容.'DESC'不是强制性的,因为它可以替换为其他任何东西.

a = <<STRING
Here
is
a
multiline
string
STRING
Run Code Online (Sandbox Code Playgroud)

<<运算符后跟一个标记文档结尾的标识符.结束标记称为终止符.终结符之前的文本行连接在一起,包括换行符和任何其他空格. http://en.wikibooks.org/wiki/Ruby_Programming/Here_documents