Edit: I just noticed @muistooshort's comment, in which he suggested the same thing that I have except for the (simple) final step (map { |k,v| { k=>v } }). μ, if you wish to post an answer, I'll delete mine.
There are many ways to do this. Here is one:
arr = [{ "acnt"=>"001" }, { "acnt"=>"001" }, { "acnt"=>"002" },
{ "acnt"=>"002" }, { "acnt"=>"003"}]
arr.flat_map(&:values).
each_with_object(Hash.new(0)) { |s,h| h[s] += 1 }.
map { |k,v| { k=>v } }
#=> [{"001"=>2}, {"002"=>2}, {"003"=>1}]
The steps are as follows:
a = arr.flat_map(&:values)
#=> ["001", "001", "002", "002", "003"]
h = a.each_with_object(Hash.new(0)) { |s,h| h[s] += 1 }
#=> {"001"=>2, "002"=>2, "003"=>1}
h.map { |k,v| { k=>v } }
#=> [{"001"=>2}, {"002"=>2}, {"003"=>1}]
{'001' => 2, '002' => 2, '003' => 3}than an array of Hashes? i.e.:arr.each_with_object({}) {|i, o| o[i[:acnt]] = (o[i[:acnt]] || 0) + 1}arr.flat_map(&:values).each_with_object(Hash.new(0)) { |v, h| h[v] += 1 }.