summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-16 06:16:15 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-16 06:16:15 +0000
commit6989f24117f4d2e90f5ec98fb30d60fff4386f9e (patch)
tree456230dae0709059a49a86a6d1a277904da66c6c /doc
parentd23857e558fe07fd82433d372183959c2ca745e6 (diff)
[DOC] Revise the character literal part.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'doc')
-rw-r--r--doc/syntax/literals.rdoc25
1 files changed, 12 insertions, 13 deletions
diff --git a/doc/syntax/literals.rdoc b/doc/syntax/literals.rdoc
index 7fcd7ca..438fd18 100644
--- a/doc/syntax/literals.rdoc
+++ b/doc/syntax/literals.rdoc
@@ -147,22 +147,22 @@ be concatenated as long as a percent-string is not last.
%q{a} 'b' "c" #=> "abc"
"a" 'b' %q{c} #=> NameError: uninitialized constant q
-One more way of writing strings is using <tt>?</tt>:
-
- ?a #=> "a"
-
-Basically only one character can be placed after <tt>?</tt>:
-
- ?abc #=> SyntaxError
-
-Exceptionally, <tt>\C-</tt>, <tt>\M-</tt> and their combination are allowed
-before a character. They mean "control", "meta" and "control-meta"
-respectively:
-
+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"
+ ?abc #=> SyntaxError
+ ?\n #=> "\n"
+ ?\s #=> " "
+ ?\\ #=> "\\"
+ ?\u{41} #=> "A"
?\C-a #=> "\x01"
?\M-a #=> "\xE1"
?\M-\C-a #=> "\x81"
?\C-\M-a #=> "\x81", same as above
+ ?あ #=> "あ"
=== 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 ")", "]", "}", ">"
respectively. You may use most other non-alphanumeric characters for percent
string delimiters such as "%", "|", "^", etc.
-