From: nobu.nokada@... Date: 2002-02-11T19:06:51+09:00 Subject: Re: array diff Hi, At Mon, 11 Feb 2002 18:17:21 +0900, Tobias Reif wrote: > I need to get the difference of two arrays; more precisely, the rest of > their intersection. (snip) > But here, > > [1,1,1] - [1,1] > -> [] > > I need to get [1]. Array#- actually treats arrays as Sets. class Array def diff(a) ary = dup a.each {|i| ary.delete_at(i) if i = ary.index(i)} ary end end p [1,2,3].diff [3,1] # => [2] p [1,2,3,3].diff [3,3,1] # => [2] p [1,1,1].diff [1,1] # => [1] -- Nobu Nakada