Ruby/String/Here Document
Материал из Wiki.crossplatform.ru
(Различия между версиями)
Версия 17:10, 26 мая 2010
Here Documents by number marker
A here document allows you to build strings from multiple lines on the fly A here document preserves newlines. A here document is formed with a << and a delimiting character or string of your choice. sonnet = <<29 W I A A W F D W Y 29 puts sonnet
HERE documents give you a shortcut for printing multiple lines to the console window
# Ruby treats any text that starts with <<TOKEN (where TOKEN can be any uppercase word) as # the beginning of a multi-line sequence, and assumes that that text ends with TOKEN. print <<HERE Now is the time HERE
Use EOF as the marker for a here document
long_string = <<EOF Here is a long string With many paragraphs EOF puts long_string