title: Move records from an array of records if matched id
body: <p>Using Rails 6.</p>
  <p><strong>My dirty code</strong></p>
  <pre><code>      active_card_ids = JSON.parse(cookies[:card_ids])
        @active_cards = []
  
        @best_cards = Houses.where(&quot;#{payment_category} IS NOT NULL&quot;).order(&quot;#{payment_category} DESC&quot;)
        @best_cards.each do |card|
          if active_card_ids.include? card.id
            @active_cards &lt;&lt; card
          end
        end
  </code></pre>
  <p><strong>What I am trying to do</strong></p>
  <p>I have an array of records queried: <code>queried_records = [&lt;object id: 1&gt;, &lt;object id: 3&gt;, &lt;object id: 4&gt;, &lt;object id: 7&gt;]</code></p>
  <p>Another array of IDs: <code>wanted_ids = [4, 5]</code></p>
  <p>Create another array: <code>selected_records = []</code></p>
  <p>I want to move <code>queried_records</code> found in <code>wanted_ids</code>, to <code>selected_records</code>.</p>
  <p>In this example, we found <code>&lt;object id: 4&gt;</code> from <code>queried_records</code>, so we want to move (not copy) it to <code>selected_records</code>.</p>
  <p>The results should be <code>selected_records</code> return an array <code>[&lt;object id: 4&gt;]</code></p>