a = %w[one two two three three three] # Ruby 2.4+ a.group_by(&:itself).transform_values(&:count) # => {"one" => 1, "two" => 2, "three" => 3} # Ruby 2.7+ a.tally # => {"one" => 1, "two" => 2, "three" => 3}