0022 Tally

Count the number of occurrences

Since version 2.7, the Enumerable module has a tally method that returns a Hash with the count of each element.

0022-tally_1.png

And since version 3.1, it accepts an optional Hash as a parameter, which it returns, to accumulate multiple counts.

0022-tally_2.png

The origin of the request was directly for tally_by (https://bugs.ruby-lang.org/issues/11076). In the meantime, you can always use the « old » way!

0022-tally_3.png

Link to Ruby documentation for tally.