From: "Stephan Kämper" Date: 2001-07-13T16:55:09+09:00 Subject: [ruby-talk:17775] Re: What is Array#- ? Dave Thomas wrote: > > Jim Freeze writes: > > > Yes, but why remove duplicates? Doesn't seem to make sense. > > I was hoping for something close to set theory. > > It's been a long time for me, but aren't sets defined _not_ to have > duplicates? > > Dave Yes. What I think is, that we have 'Array's on one side: They're not sets, because 'Array's _may_ contain elements more than once. (As far as I see there are way more efficient implementation possibilities for set than Array, but that's another question.) OTOH, we (now and then) like 'Array's to behave like an Array. Thus there is Array#-. It returns an object that fits the requirements of a set: There may or may not be any objects in it, and the objects that actually are there are unique. The point here is that Array#- works as if the Array were a set - and consquently treats it appropriately by removing duplicates. Happy rubying, Stephan