A
Aaron Patterson
Hey everyone!
I've been working with sets and I need to use them as a key in a hash.
Unfortunately, it looks like Sets are implemented as a Hash (which makes
sense), but it looks like Set#eql? calls eql? on the underlying Hash.
This seems bad to me. It means that I can't make two sets eql? to each
other.
Take this irb session for example:
I understand that sets are unordered, but it still seems weird to me
that the preceding code won't work. My workaround(?) for now is
converting the set to an array and sorting the array by hash key, and
keying on that:
=> true
I've been working with sets and I need to use them as a key in a hash.
Unfortunately, it looks like Sets are implemented as a Hash (which makes
sense), but it looks like Set#eql? calls eql? on the underlying Hash.
This seems bad to me. It means that I can't make two sets eql? to each
other.
Take this irb session for example:
=> falserequire 'set' => true
a = Set.new([1,2])=> # said:b = Set.new([1,2])=> # said:a.eql?(b)
I understand that sets are unordered, but it still seems weird to me
that the preceding code won't work. My workaround(?) for now is
converting the set to an array and sorting the array by hash key, and
keying on that:
=> true