Given that I have an array of hashes abc and a hash ghi:
abc = [{
'a' => '1',
'b' => '2',
'c' => '3',
'd' => '4'
}]
ghi = {
'a' => '1',
'b' => '2'
}
what is the cleanest and most efficient way of selecting hashes from abc that contain all of the key-value pairs in ghi?
I was able to do this:
abc.map {|n| n.slice(*ghi.keys) == ghi }.all?
although it doesn't look very clean.
In Ruby 2.3.
Note: This was answered before the OP mentioned the Ruby version.
Prior versions of Ruby: