WATANABE Hirofumi wrote:
> Jason Burgett <jasbur / gmail.com> writes:
> > ["a", "a", "a", "d", "d"]
> >
> > Then I need to somehow determine that "a" appears 3 times and "d"
> > appears 2 times. Any help would be great. Thanks.
>
> % irb
> >> a = ["a", "a", "a", "b", "c", "d", "d"]
> => ["a", "a", "a", "b", "c", "d", "d"]
> >> a.select{|i| a.grep(i).size > 1}
> => ["a", "a", "a", "d", "d"]

Taking that one step further to meet his second need:

class Array
  def duplicates_count
    uniq.map{ |e|
      if ( count = grep(e).size ) > 1
        { e => count }
      end
    }.compact
  end
end

a = ["a", "a", "a", "b", "c", "d", "d"]
p a.duplicates_count
#=> [{"a"=>3}, {"d"=>2}]