From: Charles Mills Date: 2004-08-08T00:16:11+09:00 Subject: Re: Sets are not extensional On Aug 7, 2004, at 6:11 AM, Kristof Bastiaensen wrote: > Hi, > > On Fri, 06 Aug 2004 18:08:57 +0000, Csaba Henk wrote: >> [snip] >> I've read the thread spawned by this post, and now I summarize that >> part >> of what was written there which is relevant to my original problem, >> and >> wasn't stated there explicitly. >> > > I think the thread was relevant to your post, since it described > what was causing the bug. The following should solve the problems > (but can be very slow for large Hashes/Sets): > > class Array > def hash > to_a.hash > end > end > I think you mean: class Hash def hash to_a.hash end end -Charlie > Regards, > KB > >> "Set" can be forced to behave extensionally by doing so: >> >> class Set >> def eql? other >> subset? other and other.subset? self >> end >> def hash >> to_a.hash >> end >> end >> >> -- as it seems to me, Array#uniq uses *both* of eql? and hash >> methods, and >> to get rid of the (IMHO pathological) behaviour illustrated by the >> above >> examples, both methods need to be overwritten. Concerning the above >> re-implementation of these methods, what I did with "hash" is just a >> hack, >> of course, I don't claim that it clean or right to do so, it just >> something which does the job. > >