Module: Enumerable
- Included in:
- ConfigTable
- Defined in:
- lib/roebe/core/enumerable.rb
Overview
#
Instance Method Summary collapse
-
#uniq_by ⇒ Object
# === uniq_bq.
Instance Method Details
#uniq_by ⇒ Object
#
uniq_bq
Like #uniq, but determines uniqueness based on a given block.
(-5..5).to_a.uniq_by {|i| i*i }
produces
[-5, -4, -3, -2, -1, 0]
Usage example:
array = [ ['foo','bar'], ['fii','bur'], ['foo','bas'] ]; array.uniq_by {|e| e[0] }
#
20 21 22 23 |
# File 'lib/roebe/core/enumerable.rb', line 20 def uniq_by h = {} inject([]) {|a,x| h[yield(x)] ||= a << x} end |