Ruby 文档中的何处定义了续行运算符(反斜杠)?
Where in the Ruby docs is the line continuation operator (backslash) defined?
我经常在 Ruby 文档中找不到 esoterica,这就是一个很好的例子。我可以在官方文档的哪个位置阅读有关使用反斜杠字符 \
来指示行 and/or 字符串延续的信息?谢谢!
https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html
Ruby programs are sequence of expressions. Each expression are delimited by semicolons(;) or newlines. Backslashes at the end of line does not terminate expression.
https://ruby-doc.org/docs/ruby-doc-bundle/ProgrammingRuby/book/language.html
You can also put a backslash at the end of a line to continue it onto the next.
https://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/misc.html
If a line ends with a backslash (\
), the linefeed following it is ignored; this allows you to have a single logical line that spans several lines.
https://ruby-doc.org/docs/ruby-doc-bundle/Tutorial/part_02/loops.html
You can make lines "wrap around" by putting a backslash - \
- at the very end of the line.
我猜 "most official" 记录的地方是 ISO Ruby Language Specification:
的第 8.4 节 Whitespace
whitespace ::
0x09 | 0x0b | 0x0c | 0x0d | 0x20 | line-terminator-escape-sequence
line-terminator-escape-sequence ::
\ line-terminator
其中line-terminator
又在第8.3节Line terminators中定义如下:
line-terminator ::
0x0d? 0x0a
[注:?
应该是上标,表示可选性,像这样:0x0d
?,但是写起来比较麻烦一个代码块。]
因此,将两者放在一起,表示反斜杠后跟 LF 或 CRLF 被视为空白。
我经常在 Ruby 文档中找不到 esoterica,这就是一个很好的例子。我可以在官方文档的哪个位置阅读有关使用反斜杠字符 \
来指示行 and/or 字符串延续的信息?谢谢!
https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html
Ruby programs are sequence of expressions. Each expression are delimited by semicolons(;) or newlines. Backslashes at the end of line does not terminate expression.
https://ruby-doc.org/docs/ruby-doc-bundle/ProgrammingRuby/book/language.html
You can also put a backslash at the end of a line to continue it onto the next.
https://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/misc.html
If a line ends with a backslash (
\
), the linefeed following it is ignored; this allows you to have a single logical line that spans several lines.
https://ruby-doc.org/docs/ruby-doc-bundle/Tutorial/part_02/loops.html
You can make lines "wrap around" by putting a backslash -
\
- at the very end of the line.
我猜 "most official" 记录的地方是 ISO Ruby Language Specification:
的第 8.4 节 Whitespacewhitespace :: 0x09 | 0x0b | 0x0c | 0x0d | 0x20 | line-terminator-escape-sequence line-terminator-escape-sequence :: \ line-terminator
其中line-terminator
又在第8.3节Line terminators中定义如下:
line-terminator :: 0x0d? 0x0a
[注:?
应该是上标,表示可选性,像这样:0x0d
?,但是写起来比较麻烦一个代码块。]
因此,将两者放在一起,表示反斜杠后跟 LF 或 CRLF 被视为空白。