title: Find duplicates in array of hashes on specific keys
body: <p>I have an array of hashes (CSV rows, actually) and I need to find and keep all the rows that match two specific keys (user, section). Here is a sample of the data:</p>
  
  <pre><code>[
    { user: 1, role: "staff", section: 123 },
    { user: 2, role: "staff", section: 456 },
    { user: 3, role: "staff", section: 123 },
    { user: 1, role: "exec", section: 123 },
    { user: 2, role: "exec", section: 456 },
    { user: 3, role: "staff", section: 789 }
  ]
  </code></pre>
  
  <p>So what I would need to return is an array that contained only the rows where the same user/section combo appears more than once, like so:</p>
  
  <pre><code>[
    { user: 1, role: "staff", section: 123 },
    { user: 1, role: "exec", section: 123 },
    { user: 2, role: "staff", section: 456 },
    { user: 2, role: "exec", section: 456 }
  ]
  </code></pre>
  
  <p>The double loop solution I'm trying looks like this:</p>
  
  <pre><code>enrollments.each_with_index do |a, ai|
    enrollments.each_with_index do |b, bi|
      next if ai == bi
  
      duplicates &lt;&lt; b if a[2] == b[2] &amp;&amp; a[6] == b[6]
    end
  end
  </code></pre>
  
  <p>but since the CSV is 145K rows it's taking <em>forever</em>.</p>
  
  <p>How can I more efficiently get the output I need?</p>