From: dgjones@... Date: 2018-08-21T17:55:06+00:00 Subject: [ruby-core:88598] [Ruby trunk Feature#11076] Enumerable method count_by Issue #11076 has been updated by djones (David Jones). How about `tally`? ```ruby array = ['aa', 'aA', 'bb', 'cc'] p array.tally(&:downcase) #=> {'aa'=>2,'bb'=>1,'cc'=>1} ``` `tally` describes quite well to me what this method does and avoids clashing with `group` or `count`. `tally_by` might be worthy of consideration too. ## Definition of "Tally" Current score or amount: _that takes his tally to 10 goals in 10 games._ 1. a record of a score or amount: _I kept a running tally of David's debt on a note above my desk._ 2. **a particular number taken as a group or unit to facilitate counting.** 3. a mark registering a number or amount. 4. an account kept by means of a tally. ---------------------------------------- Feature #11076: Enumerable method count_by https://bugs.ruby-lang.org/issues/11076#change-73654 * 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: