1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

refactoring uniq method

This commit is contained in:
Aaron Patterson 2010-11-16 13:34:18 -08:00
parent 7ebd36d1c4
commit 59ba800698

View file

@ -332,13 +332,10 @@ module ActiveRecord
end
def uniq(collection = self)
seen = Set.new
collection.map do |record|
unless seen.include?(record.id)
seen << record.id
record
end
end.compact
seen = {}
collection.find_all do |record|
seen[record.id] = true unless seen.key?(record.id)
end
end
# Replace this collection with +other_array+