mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[DOC] Revise the character literal part.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d23857e558
commit
6989f24117
2 changed files with 16 additions and 12 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Sep 16 15:08:17 2015 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* doc/syntax/literals.rdoc (Strings): [DOC] Revise the character
|
||||||
|
literal part.
|
||||||
|
|
||||||
Wed Sep 16 14:55:33 2015 Akinori MUSHA <knu@iDaemons.org>
|
Wed Sep 16 14:55:33 2015 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* doc/syntax/literals.rdoc (Strings): [DOC] Document the full list
|
* doc/syntax/literals.rdoc (Strings): [DOC] Document the full list
|
||||||
|
|
|
@ -147,22 +147,22 @@ be concatenated as long as a percent-string is not last.
|
||||||
%q{a} 'b' "c" #=> "abc"
|
%q{a} 'b' "c" #=> "abc"
|
||||||
"a" 'b' %q{c} #=> NameError: uninitialized constant q
|
"a" 'b' %q{c} #=> NameError: uninitialized constant q
|
||||||
|
|
||||||
One more way of writing strings is using <tt>?</tt>:
|
There is also a character literal notation to represent single
|
||||||
|
character strings, which syntax is a question mark (<tt>?</tt>)
|
||||||
|
followed by a single character or escape sequence that corresponds to
|
||||||
|
a single codepoint in the script encoding:
|
||||||
|
|
||||||
?a #=> "a"
|
?a #=> "a"
|
||||||
|
|
||||||
Basically only one character can be placed after <tt>?</tt>:
|
|
||||||
|
|
||||||
?abc #=> SyntaxError
|
?abc #=> SyntaxError
|
||||||
|
?\n #=> "\n"
|
||||||
Exceptionally, <tt>\C-</tt>, <tt>\M-</tt> and their combination are allowed
|
?\s #=> " "
|
||||||
before a character. They mean "control", "meta" and "control-meta"
|
?\\ #=> "\\"
|
||||||
respectively:
|
?\u{41} #=> "A"
|
||||||
|
|
||||||
?\C-a #=> "\x01"
|
?\C-a #=> "\x01"
|
||||||
?\M-a #=> "\xE1"
|
?\M-a #=> "\xE1"
|
||||||
?\M-\C-a #=> "\x81"
|
?\M-\C-a #=> "\x81"
|
||||||
?\C-\M-a #=> "\x81", same as above
|
?\C-\M-a #=> "\x81", same as above
|
||||||
|
?あ #=> "あ"
|
||||||
|
|
||||||
=== Here Documents
|
=== Here Documents
|
||||||
|
|
||||||
|
@ -350,4 +350,3 @@ one of the array entries you must escape it with a "\\" character:
|
||||||
If you are using "(", "[", "{", "<" you must close it with ")", "]", "}", ">"
|
If you are using "(", "[", "{", "<" you must close it with ")", "]", "}", ">"
|
||||||
respectively. You may use most other non-alphanumeric characters for percent
|
respectively. You may use most other non-alphanumeric characters for percent
|
||||||
string delimiters such as "%", "|", "^", etc.
|
string delimiters such as "%", "|", "^", etc.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue