title: Generate an HTML table from an array of hashes in Ruby
body: <p>What's the best way (ideally a gem, but a code snippet if necessary) to generate an HTML table from an array of hashes?</p>
  
  <p>For example, this array of hashes:</p>
  
  <pre><code>[{"col1"=&gt;"v1", "col2"=&gt;"v2"}, {"col1"=&gt;"v3", "col2"=&gt;"v4"}]
  </code></pre>
  
  <p>Should produce this table:</p>
  
  <pre><code>&lt;table&gt;
    &lt;tr&gt;&lt;th&gt;col1&lt;/th&gt;&lt;th&gt;col2&lt;/th&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;v1&lt;/td&gt;&lt;td&gt;v2&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;v3&lt;/td&gt;&lt;td&gt;v4&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>