ary.group_by(&:itself).map{|k, v| [k, v.size]}.to_h
でいける
irb(main):010:0> ary = %w(a b b a c) => ["a", "b", "b", "a", "c"] irb(main):011:0> ary.group_by(&:itself) => {"a"=>["a", "a"], "b"=>["b", "b"], "c"=>["c"]} irb(main):012:0> ary.group_by(&:itself).map{|k, v| [k, v.size]} => [["a", 2], ["b", 2], ["c", 1]] irb(main):013:0> ary.group_by(&:itself).map{|k, v| [k, v.size]}.to_h => {"a"=>2, "b"=>2, "c"=>1}
出現回数の多い順にソートしたい場合は
ary.group_by(&:itself).map{|k, v| [k, v.size]}.sort_by{|k, v| -v}.to_h => {"a"=>2, "b"=>2, "c"=>1}
でいける