If I create a Here document:
myheredoc = <<HTMLOUTPUT
<div>This is the div</div>
HTMLOUTPUT
Can I use 'myheredoc' to manipulate this Here document like a regular string?
If I create a Here document:
myheredoc = <<HTMLOUTPUT
<div>This is the div</div>
HTMLOUTPUT
Can I use 'myheredoc' to manipulate this Here document like a regular string?
Sure can. The syntax is there to make it easier to read, you are still just creating a string.
>> myheredoc = <<HTMLOUTPUT
<div>This is the div</div>
HTMLOUTPUT
=> "<div>This is the div</div>\n"
>> myheredoc << "<p>some paragraph</p>"
=> "<div>This is the div</div>\n<p>some paragraph</p>"
heredoc is just a syntax for generating a string. Therefore you can use all standard string methods. eg:
replaceddoc = myheredoc.gsub(/div/, 'replaced div')
There are a number of ways of declaring strings:
In all cases the strings are editable, not frozen, so yes, they can be modified after the fact.