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:
parent
7ebd36d1c4
commit
59ba800698
1 changed files with 4 additions and 7 deletions
|
@ -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
|
||||
seen = {}
|
||||
collection.find_all do |record|
|
||||
seen[record.id] = true unless seen.key?(record.id)
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
# Replace this collection with +other_array+
|
||||
|
|
Loading…
Reference in a new issue