As already noted, the heredoc text begins on the next line after the heredoc terminator. This is not intended to replace these answers, but rather provides a possible better alternative to the typical heredoc syntax.
I personally prefer using %q{} . This is equivalent to using single quotes. Below are the same results:
text = %q{ <a class="foo"> } text = ' <a class="foo"> '
If you want to use string interpolation:
text = %Q{ <a class="#{class_name}">}
You can also disable {} for other terminators. The following two lines give exactly the same result:
text = %Q[ <a class="#{class_name}">] text = %Q| <a class="#{class_name}">|
And they support multiple lines:
text = %q{<p> Some text </p>}
There are some good answers to this SO question regarding the various uses for this syntax.
source share