From: "Mark J. Reed" Date: 2003-07-30T11:07:02+09:00 Subject: Re: Set doesn't have [] instance method - and Set#| is inconsistent with Set#& On Sun, Jul 27, 2003 at 11:08:27AM +0900, Gavin Sinclair wrote: > Oh well, judging by the responses, I guess it's not all that sensible > after all. It's really not; you seem to be confusing keys with values. Consider this: myArray = [ 'a', 'b', 'c' ] If you look for myArray['a'], you will not find it; you have to use myArray.include?('a'). Sets work exactly the same way as arrays. It is hashes that are a special case, in that include? looks at keys rather than values. > I just don't like typing "include?" for something as simple as a lookup, > especially when Set (to my mind) is just a special case of Hash -- > with a bit more thrown in. It's not a lookup; it's a membership test. Sets are not Hashes - they're Arrays that don't allow duplicate values. Hashes can be used to fake Sets in languages that don't have them, because Hashes don't allow duplicate *keys* - but that's incidental to the definition. > Also since "include?" is bad grammar. First you're complaining about how much you have to type, and now you want to add another character just to make it fit English grammar? :) Just think of it as a return to the days when the subjunctive mood was used more in English. :) > Another question, then. Why does Set#| return a Set, but Set#& > returns an Array? That sounds like a bug. I would expect both to return a Set. -Mark