Skip to content

Instantly share code, notes, and snippets.

@akeem
Created December 28, 2011 14:22
Show Gist options
  • Save akeem/1528102 to your computer and use it in GitHub Desktop.
Save akeem/1528102 to your computer and use it in GitHub Desktop.
de-duping an array of Hashes based on a given hash key
#assumption that all Hashes have the de-dupe key, and the de-dupe key represents a unique
#identifier
def dedupe_by_key array,key
collector = {}
array.each{|element|
collector[element[key]] = element
}
collector.values
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment