Strings
myString << "apple"
(update
method) is faster than myString += "apple" (no extra
object creation)
Double-quote strings
- Backslash substitutions are made
#{expr} expressions are
interpolated
- The braces aren't necessary for global,
instance, and class variables
"..."
%Q{...}, %Q[...], %Q(...), %Q<...>
%Q/.../, %Q|...|
"Hello, #{expr}\n"
Backslash escapes
\" : Double quote
\\ : Backslash
\n : Linefeed
\r : Carriage return
\t : Tab
\s : Space
\x[0-9A-Fa-f]{1,2} : Character value in hexadecimal.
\[0-7]{1,3} : Character value in octal.
Single-quote strings
- Very little processing is done to the
string
'...'
%q{...}, %q[...], %q(...), %q<...>
%q/.../, %q|...|
Backslash escapes
\' : Single quote
\\ : Backslash
Multi-line strings
str = "Multi-line" \
"string"
- Append a backslash character to the end
of every non-final
line.
Heredoc text
<<IDENTIFIER | QUOTED_STRING
...
IDENTIFIER | QUOTED_STRING
- If add a minus sign after the
<<,
can indent the closing identifier / quoted string