Histograma Enumerável

module Enumerable

def to_histogram
inject
(Hash.new(0)) { |h, x| h[x] += 1; h}
end

end
%w(a b c d a a b).to_histogram

retornará:
{
“a” => 3,
“b” => 2,
“c” => 1,
“d” => 1
}