Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created September 26, 2012 09:53
Show Gist options
  • Save jackfranklin/3787094 to your computer and use it in GitHub Desktop.
Save jackfranklin/3787094 to your computer and use it in GitHub Desktop.
Ruby object filtering in arrays
my_data = [
{
:foo => 1
#etc
},
{
:foo => 2
#etc
},
{
:foo => 1 #duplicate property, should be removed
#etc
}
]
# how would I write some code to go through this array, and remove any objects that have a foo property the same as a previous object in the array?
@tombeynon
Copy link

my_data.uniq { |h| h[:foo] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment