Actions
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
Actions
Like0
Like0