34,333
edits
Changes
→Ruby Here Documents
== Ruby Here Documents ==
A ''Here Document'' (or ''heredoc'' as it is more commonly referred to) provides a mechanism for creating free format strings, preserving special characters such as new lines and tabs.
A here document is created by preceding the text with '<<'' followed by the delimimter string you wish to use to mark the end of the text. The following example uses the string "DOC" as the delimiter:
<pre>
myText = <<DOC
Please Detach and retrn this coupon with your payment.
Do not send chas or coins.
Please write your name and account number on the check and
make checks payable to:
Acme Corporation
Thank you for your business.
DOC
</pre>
When this string is printed to appears exactly as it was entered, together with all the new lines and tabs:
<pre>
puts myText
Please Detach and retrn this coupon with your payment.
Do not send chas or coins.
Please write your name and account number on the check and
make checks payable to:
Acme Corporation
Thank you for your business.
</pre>