%w(foo foo bar foo baz foo).tally
# => {"foo"=>4, "bar"=>1, "baz"=>1}

Source: Ruby 2.7 - Enumerable#tally - Brandon Weaver - Medium

Sounds familiar: I use this count_by method (previously discussed on this blog) on occasion.