Ruby 的字符串文字并列功能在哪里有官方记录? [英] Where is Ruby's string literal juxtaposition feature officially documented?

查看:55
本文介绍了Ruby 的字符串文字并列功能在哪里有官方记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近意识到,如果您将一系列 Ruby 字符串文字并列(例如 'a' "b" 'c'),则相当于这些字符串文字的串联.但是,我无法在任何地方找到此语言功能的记录.我使用术语并置"和串联"进行了搜索,但只在几个 StackOverflow 响应中找到了对它的引用.谁能给我一个明确的参考资料?

I recently realized that if you juxtapose a sequence of Ruby string literals (e.g. 'a' "b" 'c'), it's equivalent to the concatenation of those string literals. However, I can't find this language feature documented anywhere. I've searched using the terms "juxtaposition" and "concatenation", but only found reference to it in a couple of StackOverflow responses. Can anyone point me to a definitive reference?

推荐答案

UPDATE

这是现在正式记录在 Ruby 随附的 RDoc 中.

更改将传播到 RubyDoc 下次他们构建文档时.

Changes will propagate to RubyDoc the next time they build the documentation.

添加的文档:

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

我在 拉取请求/github.com/ruby/ruby" rel="noreferrer">ruby/ruby 并添加了文档.

I've opened a pull request on ruby/ruby with the documentation added.

如果这个pull request被合并了,它会自动更新http://www.ruby-doc.org.如果/当发生这种情况时,我会更新这篇文章.^_^

If this pull request is merged, it will automatically update http://www.ruby-doc.org. I'll update this post if/when that happens. ^_^

我在网上找到的唯一其他提及的是:

The only other mentions of this I've found online are:

  • The Ruby Programming Language, page 47 (mentioned in another answer)
  • Ruby Forum Post circa 2008
  • Programming Ruby

这篇关于Ruby 的字符串文字并列功能在哪里有官方记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆