我最近意识到,如果你并置一系列Ruby字符串文字(例如'a' "b" 'c'),它就相当于这些字符串文字的串联.但是,我无法在任何地方找到此语言功能.我使用术语"并置"和"连接"进行了搜索,但只在几个StackOverflow响应中找到了对它的引用.谁能指出我一个明确的参考?
Chr*_*ler 10
下次构建文档时,更改将传播到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
Run Code Online (Sandbox Code Playgroud)
现在,这不是官方ruby文档中的任何地方,但我认为应该如此.正如评论中所指出的,文档的合理位置是:http://www.ruby-doc.org/core-2.0/doc/syntax/literals_rdoc.html#label-Strings
我已经添加了文档,在ruby/ruby上打开了一个pull请求.
如果合并此拉取请求,它将自动更新http://www.ruby-doc.org.如果发生这种情况,我会更新这篇文章.^ _ ^
我在网上发现的唯一其他提及是: