Skip to content

Instantly share code, notes, and snippets.

@rf-
Created August 11, 2011 22:35
Show Gist options
  • Save rf-/1140983 to your computer and use it in GitHub Desktop.
Save rf-/1140983 to your computer and use it in GitHub Desktop.
arr = [[{:name=>"one", :enabled=>true},
{:name=>"two", :enabled=>false}],
[{:name=>"one", :enabled=>true},
{:name=>"two", :enabled=>true}]
]
a = arr.flatten.inject(Hash.new(true)) do |result, element|
result[element[:name]] &&= element[:enabled]
result
end.map do |key, value|
{:name => key, :enabled => value}
end
p a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment