[Ruby] eql? and hash on Sets

Aaron Patterson aaron at tenderlovemaking.com
Sat Nov 24 10:35:15 PST 2007


Given the behavior of Array#hash and Array#eql?, what would you expect
Set#hash and Set#eql? to do?  I expected Set to behave the same way as
Array, but it does not.  That kind of made sense since you cannot
guarantee order in a Set.  However, I was surprised to find that Set
implements eql? and hash.  That leads me to believe that the original
intent was for Set to behave like Array in that department, and that
this is a bug.  As far as I can tell, no two Sets can eql? each other.

Does anyone have thoughts on this?  I was able to monkey patch Set so
that those methods work the way I expect, although the methods get
slower as the set gets larger.

-- 
Aaron Patterson
http://tenderlovemaking.com/


More information about the Ruby mailing list