Strings in Ruby

Watch out! This tutorial is over 4 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.
Tutorial Difficulty Level    

Ruby has many ways of making strings, which are generally variations of the many ways Perl has of making strings. Double quotes allow values to be interpolated into the string, while single quotes do not. Most escapes are treated literally in single quotes, including the fact that \n is treated as two characters, a backward slash followed by an n.

Ruby strings may extend any number of lines. This can be useful, but make sure you don’t leave out any closing quotes.

The << notation follows Perl and other languages as a way to multi-line strings. Those don’t generally permit the other varieties to specify multi-line strings, so it’s actually kind of redundant in Ruby.

The % can be used to create strings using a different delimiter. %Qx starts a double-quote style string which ends with the next x, rather than the usual double quote character. %qy starts a single-quote string.