Ruby的string字面并置function在哪里正式logging?

我最近意识到,如果你并置一串Rubystring文本(例如'a' "b" 'c' ),它就等同于这些string文字的连接。 但是,我无法在任何地方find这种语言function。 我search使用的术语“并置”和“串联”,但只发现在几个StackOverflow响应的引用。 任何人都可以指出我一个明确的参考?

UPDATE

这现在已经正式logging在Ruby附带的RDoc中。

下次构build文档时,更改将传播到RubyDoc 。

添加的文档:

 Adjacent string literals are automatically concatenated by the interpreter: "con" "cat" "en" "at" "ion" #=> "concatenation" "This string contains "\ "no newlines." #=> "This string contains no newlines." Any combination of adjacent single-quote, double-quote, percent strings will be concatenated as long as a percent-string is not last. %q{a} 'b' "c" #=> "abc" "a" 'b' %q{c} #=> NameError: uninitialized constant q 

原版的

现在,这不是官方的Ruby文档中的任何地方,但我认为它应该是。 正如在评论中指出的,文档的合理位置是: http : //www.ruby-doc.org/core-2.0/doc/syntax/literals_rdoc.html#label-Strings

我已经打开了一个ruby / ruby与添加文档的拉请求 。

如果这个拉取请求被合并,它会自动更新http://www.ruby-doc.org 。 如果发生这种情况,我会更新这篇文章。 ^ _ ^

我在网上发现的唯一的其他提到的是:

  • Ruby编程语言,第47页 (在另一个答案中提到)
  • Ruby Forum Post大约在2008年
  • 编程Ruby

Ruby编程语言(第47页 )中提供了一个参考。

它看起来像故意在parsing器中的情况下,你想要在代码中分割string文字,但不想支付连接它们的价格(并创build3个或更多的string)。 没有换行符的长string,并且不需要行长度的破坏代码就是一个很好的例子

 text = "This is a long example message without line breaks. " \ "If it were not for this handy syntax, " \ "I would need to concatenate many strings, " \ "or find some other work-around" 

除了镐参考 ,还有一些unit testing :

 # compile time string concatenation assert_equal("abcd", "ab" "cd") assert_equal("22aacd44", "#{22}aa" "cd#{44}") assert_equal("22aacd445566", "#{22}aa" "cd#{44}" "55" "#{66}") 

如果你想要在多行中打断一个单引号的长string而不embedded新行。

简单地把它分解成多个相邻的string文字,Ruby解释器会在parsing过程中连接它们。

 str = "hello" "all" puts str #=> helloall 

记住,你必须逃避文字之间的换行符,这样ruby才不会将新行解释为语句终结符。

 str = "hello" \ " all" \ " how are you." puts str #=> hello all how are you