Strings (Part 3)

There are more ways of constructing string literals such as %q, %Q and “here documents.” The first two are used to starte single or double-quoted strings such as;

%q/general single-quoted string/ >> general single-quoted string
%Q!general single-quoted string! >> general double-quoted string
%Q{Seconds/day: #{24*60*60}} >> Seconds/day: 86400

The character following the “q” or “Q” is the delimiter that if it is an opening bracket, brace, parenthisis or a less than sign, the string is read tilla matching closing symbol is found, if not it continues on reading till the next ocurence of the same delimiter is found. The last type of string literal is the “here document” shown below.

a String = <<END_OF_STRING
The body of the string is the
input lines up to the one line
that ends with the same text
that followed the ‘<<’
END_OF_STRING

This entry was posted in Development, Programming Basics and tagged , . Bookmark the permalink. Comments are closed, but you can leave a trackback: Trackback URL.