title: How to match and replace templating tags in Ruby / Rails?
body: <p>Trying to add a very rudimentary description template to one of my Rails models. What I want to do is take a template string like this:</p>
  
  <pre><code>template = "{{ name }} is the best {{ occupation }} in {{ city }}."
  </code></pre>
  
  <p>and a hash like this: </p>
  
  <pre><code>vals = {:name =&gt; "Joe Smith", :occupation =&gt; "birthday clown", :city =&gt; "Las Vegas"}
  </code></pre>
  
  <p>and get a description generated. I thought I could do this with a simple gsub but Ruby 1.8.7 doesn't accept hashes as the second argument. When I do a gsub as a block like this: </p>
  
  <pre><code>&gt; template.gsub(/\{\{\s*(\w+)\s*\}\}/) {|m| vals[m]}
  =&gt; " is the best  in ." 
  </code></pre>
  
  <p>You can see it replaces it with the entire string (with curly braces), not the match captures. </p>
  
  <p>How do I get it to replace "{{ something }}" with vals["something"] (or vals["something".to_sym])?</p>
  
  <p>TIA</p>