From: Harry Kakueki Date: 2010-07-21T00:26:08+09:00 Subject: Re: Count occurences of vars in array On Tue, Jul 20, 2010 at 11:25 PM, Vitaliy Yanchuk wrote: > Jean-Julien Fleck, thanks. > Maybe have an idea of a one-line version? :) > Try this or something like this. I'm very sleepy ZZZZZZZZZZZ arr = ["a", "b", "a", "c", "c", "b", "b"] p Hash[*(arr.uniq.map{|x| [x,arr.select{|y| y == x}.length]}).flatten] #> {"a"=>2, "b"=>3, "c"=>2} Harry