title: Using "AND" operation to select hashes from array of hashes in ruby
body: <pre><code>input = [ {"name" =&gt; "adam",  "nick" =&gt; ["kuruvi", "cali"] },
            {"name" =&gt; "eve",   "nick" =&gt; ["cali"]           },
            {"name" =&gt; "enoch", "nick" =&gt; []                 },    
            {"name" =&gt; "ebe",   "nick" =&gt; ["test", "wrong"]  },
            {"name" =&gt; "fred",  "nick" =&gt; ["da"]             } ]
  </code></pre>
  
  <p>I want to select hashes which contains <code>"da"</code> &amp; <code>"cali"</code> in <code>"nick"</code>.</p>
  
  <pre><code>input.select do |d|
    d["nick"].include?("cali")
  end
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>[{"name"=&gt;"adam", "nick"=&gt;["kuruvi", "cali"]},
   {"name"=&gt;"eve", "nick"=&gt;["cali"]}]
  </code></pre>
  
  <p>How can we include two parameters in check. Eg: <code>include?("cali","da")</code> so that my result will be</p>
  
  <pre><code> [{"name"=&gt;"adam", "nick"=&gt;["kuruvi", "cali"]},
    {"name"=&gt;"eve", "nick"=&gt;["cali"]},
    {"name" =&gt; "fred",  "nick" =&gt; ["da"]}]
  </code></pre>
  
  <p>Tried this</p>
  
  <pre><code> i = ["da","cali"]
   input.select do |d|
     d["nick"].all? { |v| i.include? v }
   end
  
  =&gt; [{"name" =&gt; "adam",  "nick" =&gt; ["kuruvi", "cali"]},
      {"name" =&gt; "eve",   "nick" =&gt; ["cali"]},
      {"name" =&gt; "enoch", "nick" =&gt; []},
      {"name" =&gt; "fred",  "nick" =&gt; ["da"]}]
  </code></pre>
  
  <p>(but this returns hashes with <code>"nick"=[]</code> also)</p>