Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/tarvit-helpers/extensions/counter.rb
Instance Method Summary collapse
Instance Method Details
#count_by_rule(&rule) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/tarvit-helpers/extensions/counter.rb', line 13 def count_by_rule(&rule) info_by_rule(->(x){ x.count }){|x| rule.(x) } end |
#info_by_rule(info, &rule) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/tarvit-helpers/extensions/counter.rb', line 3 def info_by_rule(info, &rule) counts = self.group_by{|x| rule.(x) }.to_a.map{|x| x[1] = info.(x[1]) x } Hash[counts] end |