Class: Array

Inherits:
Object show all
Defined in:
lib/core_ext/array.rb

Instance Method Summary collapse

Instance Method Details

#group_by(&blk) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/core_ext/array.rb', line 2

def group_by(&blk)
  Hash.new { |h,k| h[k] = [] }.tap do |hash|
    each do |element|
      hash[blk.call(element)] << element
    end
  end
end