From: David Alan Black Date: 2002-02-11T23:23:08+09:00 Subject: Re: array diff Hi -- On Mon, 11 Feb 2002, Tobias Reif wrote: > Florian, > > thanks to Hugh, I realized that > > class Array > def minus other > out = self.dup > other.each do |el| > if out.index(el) > out.delete_at out.index(el) > end > end > out > end > end > > is better. But didn't you want: [1,1].minus([1,1,1]) => [1] ? If so, you'd have to differentiate the arrays based on size: class Array def minus other (long,short) = [self,other].max.dup, [self,other].min short.each do |el| if long.index(el) long.delete_at long.index(el) end end long end end (Mind you, I think the #delete_at could get slow with big arrays, since it's rewriting the array so often.) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav