Module: Enumerable
- Defined in:
- lib/rubyc/core_extensions.rb
Instance Method Summary collapse
Instance Method Details
#count_by ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/rubyc/core_extensions.rb', line 2 def count_by self.inject({}) do |memo, elem| key = yield elem memo[key] ||= 0 memo[key] += 1 memo end end |
#uniq_by ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rubyc/core_extensions.rb', line 11 def uniq_by each_with_index.inject({}) do |memo, (obj, index)| val, data = yield obj memo[val] ||= data memo end.values end |