Project

General

Profile

Actions

Feature #11076

closed

Enumerable method count_by

Added by haraldb (Harald Böttiger) over 9 years ago. Updated over 5 years ago.

Status:
Closed
Target version:
-
[ruby-core:<unknown>]

Description

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}
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0