summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/syntax/literals.rdoc46
1 files changed, 44 insertions, 2 deletions
diff --git a/doc/syntax/literals.rdoc b/doc/syntax/literals.rdoc
index 194945abbd..aadd574a97 100644
--- a/doc/syntax/literals.rdoc
+++ b/doc/syntax/literals.rdoc
@@ -83,8 +83,33 @@ Any internal <tt>"</tt> must be escaped:
"This string has a quote: \". As you can see, it is escaped"
-Double-quote strings allow escaped characters such as <tt>\n</tt> for newline,
-<tt>\t</tt> for tab, etc.
+Double-quote strings allow escaped characters such as <tt>\n</tt> for
+newline, <tt>\t</tt> for tab, etc. The full list of supported escape
+sequences are as follows:
+
+ \a bell, ASCII 07h (BEL)
+ \b backspace, ASCII 08h (BS)
+ \t horizontal tab, ASCII 09h (TAB)
+ \n newline (line feed), ASCII 0Ah (LF)
+ \v vertical tab, ASCII 0Bh (VT)
+ \f form feed, ASCII 0Ch (FF)
+ \r carriage return, ASCII 0Dh (CR)
+ \e escape, ASCII 1Bh (ESC)
+ \s space, ASCII 20h (SPC)
+ \\ backslash, \
+ \nnn octal bit pattern, where nnn is 1-3 octal digits ([0-7])
+ \xnn hexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F])
+ \unnnn Unicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F])
+ \u{nnnn ...} Unicode character(s), where each nnnn is 1-6 hexadecimal digits ([0-9a-fA-F])
+ \cx or \C-x control character, where x is an ASCII printable character
+ \M-x meta character, where x is an ASCII printable character
+ \M-\C-x meta control character, where x is an ASCII printable character
+ \M-\cx same as above
+ \c\M-x same as above
+ \c? or \C-? delete, ASCII 7Fh (DEL)
+
+Any other character following a backslash is interpreted as the
+character itself.
Double-quote strings allow interpolation of other values using
<tt>#{...}</tt>:
@@ -124,6 +149,23 @@ 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:
+
+ ?\C-a #=> "\x01"
+ ?\M-a #=> "\xE1"
+ ?\M-\C-a #=> "\x81"
+ ?\C-\M-a #=> "\x81", same as above
+
=== Here Documents
If you are writing a large block of text you may use a "here document" or