title: How can I get the intersection, union, and subset of arrays in Ruby?
body: <p>I want to create different methods for a class called <a href="http://en.wikipedia.org/wiki/Multiset">Multiset</a>.</p>
  
  <p>I have all the required methods, but I'm unsure of how to write intersection, union, and subset methods.</p>
  
  <p>For intersection and union, my code starts like this:</p>
  
  <pre><code>def intersect(var)
    x = Multiset.new
  end
  </code></pre>
  
  <p>Here is an example:</p>
  
  <pre><code>X = [1, 1, 2, 4]
  Y = [1, 2, 2, 2]
  </code></pre>
  
  <p>then the intersection of <code>X</code> and <code>Y</code> is <code>[1, 2]</code>. </p>