Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/rails2ext/active_support/core_ext/array/uniq_by.rb
Instance Method Summary collapse
-
#uniq_by ⇒ Object
Returns an unique array based on the criteria given as a
Proc
.
Instance Method Details
#uniq_by ⇒ Object
Returns an unique array based on the criteria given as a Proc
.
[1, 2, 3, 4].uniq_by { |i| i.odd? } # => [1, 2]
6 7 8 9 10 |
# File 'lib/rails2ext/active_support/core_ext/array/uniq_by.rb', line 6 def uniq_by hash, array = {}, [] each { |i| hash[yield(i)] ||= (array << i) } array end |