title: Indent multiline string in ERB
body: <p>I have a string from an external library that looks like this:</p>
  
  <pre><code>s = "  things.each do |thing|\n    thing += 5\n    thing.save\n  end\n\n"
  </code></pre>
  
  <p>This input string isn't going to change. I need to insert it into a file using ERB. e.g.:</p>
  
  <pre><code>erb = ERB.new("&lt;%= s %&gt;")
  File.write("test.txt", erb.result(instance_eval('binding'))
  </code></pre>
  
  <p>My problem is the indentation. Without making any changes to the string, the file will be written like this:</p>
  
  <pre><code>  things.each do |thing|
      thing += 5
      thing.run
    end
  </code></pre>
  
  <p>Note the indentation. What I want to do, however, is to insert the text uniformly indented another two spaces in, like so:</p>
  
  <pre><code>    things.each do |thing|
        thing += 5
        thing.run
      end
  </code></pre>
  
  <p>If I do this:</p>
  
  <pre><code>erb = ERB.new("  &lt;%= s %&gt;")
  </code></pre>
  
  <p>Then only the first line will be indented.</p>
  
  <pre><code>    things.each do |thing|
      thing += 5
      thing.run
    end
  </code></pre>
  
  <p>I <em>can</em> achieve this by modifying the initial string..</p>
  
  <pre><code>erb = ERB.new("&lt;%= s.gsub(/  (\w)/, "    \\1") %&gt;")
  </code></pre>
  
  <p>.. but that feels a bit messy. I don't really want to do that in the view. Is there a way to indent the entire string in ERB, or am I out of luck? I think I might be.</p>