Created
September 26, 2012 09:53
-
-
Save jackfranklin/3787094 to your computer and use it in GitHub Desktop.
Ruby object filtering in arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my_data.uniq { |h| h[:foo] }