From: Jimmy Kofler Date: 2009-01-15T20:18:54+09:00 Subject: Re: Returning a duplicate from an Array > Pierre Pat wrote: > I'd do like this: > a.select{|x| a.index(x) != a.rindex(x)}.uniq > > Now, I wouldn't know which one is more efficient, but coding wise, I > like that way :-) Here's yet another take on it: class Array def dups uniq.select{ |e| (self-[e]).size < self.size - 1 } end end p [ 1, 1, 2, 2, 3, 3, 4, 5 ].dups #=> [1, 2, 3] see: http://snippets.dzone.com/posts/show/4148 Cheers, j.k. -- Posted via http://www.ruby-forum.com/.