Module: ViewModel::Utils::Collections
- Defined in:
- lib/view_model/utils/collections.rb
Class Method Summary collapse
Class Method Details
.count_by(enumerable) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/view_model/utils/collections.rb', line 5 def self.count_by(enumerable) enumerable.each_with_object({}) do |el, counts| key = yield(el) unless key.nil? counts[key] = (counts[key] || 0) + 1 end end end |