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 => [1,2,3,4,5,6]},
{:blocks => [1,2,3]},
{:blocks => [4,5,6]}
]
titles = titles.delete_if.each_with_index {|candidate, index|
title_contains_blocks(candidate, titles, index)
}
puts titles.inspect
#=> [{:blocks=>[1, 2, 3]}, {:blocks=>[4, 5, 6]}]