Issue #11076 has been updated by Robert A. Heiler.


Can you also add a sentence or two for documentation? :-)

It may lower the entry barrier for adding a method such as the above (I assume it must be documented by someone before it could be added).

----------------------------------------
Feature #11076: Enumerable method count_by
https://bugs.ruby-lang.org/issues/11076#change-52197

* Author: Harald Bttiger
* Status: Open
* Priority: Low
* Assignee: 
----------------------------------------
I very often use `Hash[array.group_by{|x|x}.map{|x,y|[x,y.size]}]`.

Would be nice with to have a method called `count_by`:

    array = ['aa', 'aA', 'bb', 'cc']
    p array.count_by(&:downcase) #=> {'aa'=>2,'bb'=>1,'cc'=>1}



-- 
https://bugs.ruby-lang.org/