names = ["Jason", "Jason", "Teresa", "Judah", "Michelle", "Judah", "Judah", "Allison"] counts = names.each_with_object(Hash.new(0)){ |string, hash| hash[string] += 1 } puts counts # => { Jason: 2, Teresa: 1, Judah: 3, ... }