Module: Webhookdb::Enumerable

Defined in:
lib/webhookdb/enumerable.rb

Class Method Summary collapse

Class Method Details

.group_and_count(enumerable) ⇒ Object



15
16
17
# File 'lib/webhookdb/enumerable.rb', line 15

module_function def group_and_count(enumerable)
  return group_and_count_by(enumerable) { |k| k }
end

.group_and_count_by(enumerable) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/webhookdb/enumerable.rb', line 6

module_function def group_and_count_by(enumerable)
  result = Hash.new(0)
  enumerable.each do |item|
    key = yield(item)
    result[key] += 1
  end
  return result
end