instance method
uniq_by
Ruby on Rails 3.2.22.5
Since v3.0.20 Last seen in v4.0.13Signature
uniq_by()
Returns an unique array based on the criteria given as a Proc.
[1, 2, 3, 4].uniq_by { |i| i.odd? } # => [1, 2]
Source
# File activesupport/lib/active_support/core_ext/array/uniq_by.rb, line 6
def uniq_by
hash, array = {}, []
each { |i| hash[yield(i)] ||= (array << i) }
array
end
Defined in activesupport/lib/active_support/core_ext/array/uniq_by.rb line 6
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Array