From: Kristof Bastiaensen Date: 2004-08-08T03:16:33+09:00 Subject: Re: Sets are not extensional On Sun, 08 Aug 2004 00:16:11 +0900, Charles Mills wrote: > 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 > I did. Thanks! KB >> 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. >> >> >>