What\'s the most elegant way to select out objects in an array that are unique with respect to one or more attributes?
These objects are stored in ActiveRecord so us
I had originally suggested using the select method on Array. To wit:
select
[1, 2, 3, 4, 5, 6, 7].select{|e| e%2 == 0} gives us [2,4,6] back.
[1, 2, 3, 4, 5, 6, 7].select{|e| e%2 == 0}
[2,4,6]
But if you want the first such object, use detect.
detect
[1, 2, 3, 4, 5, 6, 7].detect{|e| e>3} gives us 4.
[1, 2, 3, 4, 5, 6, 7].detect{|e| e>3}
4
I'm not sure what you're going for here, though.