title: Evaluating string templates
body: <p>I have a string template as shown below</p>
  <pre><code>template = '&lt;p class=&quot;foo&quot;&gt;#{content}&lt;/p&gt;'
  </code></pre>
  <p>I want to evaluate the template based on current value of the variable called <code>content</code>.</p>
  <pre><code>html = my_eval(template, &quot;Hello World&quot;)
  </code></pre>
  <p>This is my current approach for this problem:</p>
  <pre><code>def my_eval template, content
    &quot;\&quot;#{template.gsub('&quot;', '\&quot;')}\&quot;&quot;  # gsub to escape the quotes
  end
  </code></pre>
  <p>Is there a better approach to solving this problem?</p>
  <h1>EDIT</h1>
  <p>I used HTML fragment in the sample code above to demonstrate my scenario. My real scenario has set of XPATH templates in a configuration file. The bind variables in the template are substituted to get a valid XPATH string.</p>
  <p>I have thought about using ERB, but decided against as it might be a overkill.</p>