Browse files

Refactor association_collection uniq method.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent e1e39a9 commit abb99e3ac071fc98307c7f3502fdada7426ea39e @miloops miloops committed with spastorino Sep 22, 2010
Showing with 3 additions and 4 deletions.
  1. +3 −4 activerecord/lib/active_record/associations/association_collection.rb
View
7 activerecord/lib/active_record/associations/association_collection.rb
@@ -338,13 +338,12 @@ def many?
def uniq(collection = self)
seen = Set.new
- collection.inject([]) do |kept, record|
+ collection.map do |record|
unless seen.include?(record.id)
- kept << record
seen << record.id
+ record
end
- kept
- end
+ end.compact
end
# Replace this collection with +other_array+

0 comments on commit abb99e3

Please sign in to comment.