From: sawadatsuyoshi@... Date: 2019-02-02T03:01:09+00:00 Subject: [ruby-core:91380] [Ruby trunk Feature#11076] Enumerable method count_by Issue #11076 has been updated by sawa (Tsuyoshi Sawada). knu (Akinori MUSHA) wrote: > In today's developer meeting, Matz understood the need for the feature but didn't like the name. One point he made was that existing pairs like sort/sort_by and max/max_by share their features, so count_by() might not go well with count(). Since this feature is an inferior variant of `group_by` in the sense that it reduces the value arrays into their lengths, what about naming the method `group`? ---------------------------------------- Feature #11076: Enumerable method count_by https://bugs.ruby-lang.org/issues/11076#change-76635 * Author: haraldb (Harald B��ttiger) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- 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`: ~~~ruby array = ['aa', 'aA', 'bb', 'cc'] p array.count_by(&:downcase) #=> {'aa'=>2,'bb'=>1,'cc'=>1} ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: