Class: Array

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

Instance Method Summary collapse

Instance Method Details

#group_by(&block) ⇒ Object

Raises:

  • (ArgumentError)


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

def group_by(&block)
  raise ArgumentError unless block
  inject({}) do |hash, elem|
    key = block.call(elem)
    hash[key] ||= []
    hash[key].push(elem)
    hash
  end
end