Project

General

Profile

Actions

Bug #1846

closed

Unexpected behavior of hash of array

Added by phasis68 (Heesob Park) over 15 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]
Backport:
[ruby-core:24638]

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 #1

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

Actions

Also available in: Atom PDF

Like0
Like0