title: How to dynamically generate a map in Ruby
body: <p>I have the following code</p>
  <pre><code>records.map do |record|
    {
      id: record.id,
      uuid: record.uuid
    }
  end
  </code></pre>
  <p>but I would like portions of it to be created dynamically, i.e if I had the array <code>COLUMNS = [&quot;id&quot;, &quot;uuid&quot;, &quot;name&quot;]</code></p>
  <p>How could I have it generate the below based on the array automatically?</p>
  <pre><code>records.map do |record|
    {
      id: record.id,
      uuid: record.uuid,
      name: record.name
    }
  end
  </code></pre>
  <p>i.e.</p>
  <pre><code>records.map do |record|
    {
      COLUMNS[0]: record.COLUMNS[0],
      COLUMNS[1]: record.COLUMNS[1],
      COLUMNS[2]: record.COLUMNS[2]
    }
  end
  </code></pre>
  <p>Thanks!</p>