In the code below it appears Ruby is permitting duplicate keys. What's
happening?
--Brian
h = {}
h[{}] = "test1" #key is an empty hash
h[{}] = "test2" #2nd key is an empty hash -- two duplicate keys?
h.size # 2
{} == {} # => true empty hashes are equal
{}.eql? {}
# => false
{}.hash == {}.hash
# => false
I don't think Hash uses == at all.
···
On Thu, 2006-03-23 at 05:56 +0900, Brian Buckley wrote:
In the code below it appears Ruby is permitting duplicate keys. What's
happening?
--Brian
h = {}
h[{}] = "test1" #key is an empty hash
h[{}] = "test2" #2nd key is an empty hash -- two duplicate keys?
h.size # 2
{} == {} # => true empty hashes are equal
--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk
The two empty hashes are equal, but they're not the same empty hash, if that makes sense. Try this:
irb(main):013:0> {}.object_id == {}.object_id
=> false
I hope this answers your question!
Cheers,
Eric
···
On Mar 22, 2006, at 3:56 PM, Brian Buckley wrote:
In the code below it appears Ruby is permitting duplicate keys. What's
happening?
--Brian
h = {}
h[{}] = "test1" #key is an empty hash
h[{}] = "test2" #2nd key is an empty hash -- two duplicate keys?
h.size # 2
{} == {} # => true empty hashes are equal