refactoring uniq method
This commit is contained in:
parent
7ebd36d1c4
commit
59ba800698
@ -332,13 +332,10 @@ def many?
|
||||
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+
|
||||
|
Loading…
Reference in New Issue
Block a user