End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Enumerable#tally
enum.tally → a_hash
enum.c
View on GitHub ↗
static VALUE
enum_tally(VALUE obj)
{
return enum_hashify(obj, 0, 0, tally_i);
}
Tallies the collection, i.e., counts the occurrences of each element. Returns a hash with the elements of the collection as keys and the corresponding counts as values.
Example
["a", "b", "c", "b"].tally #=> {"a"=>1, "b"=>2, "c"=>1}