Bug #1846
closedUnexpected behavior of hash of array
Description
=begin
I noticed some unexpected behaviors of hash with array key
irb(main):001:0> h={}
=> {}
irb(main):002:0> a=[]
=> []
irb(main):003:0> h[a]=1
=> 1
irb(main):004:0> a<<1
=> [1]
irb(main):005:0> h[a]=2
=> 2
irb(main):006:0> a<<2
=> [1, 2]
irb(main):007:0> h[a]=3
=> 3
irb(main):008:0> h
=> {[1, 2]=>1, [1, 2]=>2, [1, 2]=>3}
irb(main):009:0> h[a]
=> 3
irb(main):010:0> h[[1,2]]
=> 3
irb(main):011:0> Marshal.load(Marshal.dump(h))
=> {[1, 2]=>3}
irb(main):012:0> h.delete(a)
=> 3
irb(main):013:0> h
=> {[1, 2]=>1, [1, 2]=>2}
irb(main):014:0> h[a]
=> nil
irb(main):015:0> h.delete(a)
=> 1
irb(main):016:0> h
=> {[1, 2]=>2}
irb(main):017:0> h[a]
=> nil
irb(main):018:0> h.delete(a)
=> nil
=end
Updated by shyouhei (Shyouhei Urabe) over 15 years ago
- Status changed from Open to Rejected
=begin
This is a designed behaviour. Every time you change any key object of a hash, you have to call that hash's rehash method.
=end