mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
refactoring uniq method
This commit is contained in:
@@ -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+
|
||||
|
||||
Reference in New Issue
Block a user