Comparing hash members to other hash members I've written a script that deletes a member of a hash if an array within the has contains all the other elements of another array within the same hash.

It works but it looks a little messy. Is there a better way to do this?

def title_contains_blocks(candidate, titles, index)
  test_group = titles.dup
  test_group.delete_at(index)
  test_group.each do |title|
    return true if true === title[:blocks].all?{|block| candidate[:blocks].include?(block)}
  end

  return false
end

titles = [
  {:blocks =&gt; [1,2,3,4,5,6]},
  {:blocks =&gt; [1,2,3]},
  {:blocks =&gt; [4,5,6]}
]

titles = titles.delete_if.each_with_index {|candidate, index| 
  title_contains_blocks(candidate, titles, index)
}

puts titles.inspect
#=&gt; [{:blocks=&gt;[1, 2, 3]}, {:blocks=&gt;[4, 5, 6]}]
Convert the Hashes to Arrays, then use the difference operations on them.

a = { :a =&gt; 1, :b =&gt; 2, :c =&gt; 2 }
b = { :a =&gt; 1 }

p (b.to_a - a.to_a).empty?


You can do other things, like identify if two Hashes overlap in any places, by use the intersection too:

p (a.to_a &amp; b.to_a).any?