From: Alan Stebbens Date: 2009-08-27T13:36:49+09:00 Subject: [ruby-core:25159] [Bug #2004] Setting Hash default to an array hides the hash keys Issue #2004 has been updated by Alan Stebbens. File good1.rb added This is the same code, except without an array default value (using code to initialize a default for each key): $ cat good1.rb #!/usr/bin/env ruby h = Hash.new d = ['a', 'b', 'c'] puts h d.each_with_index{|k,x| h[k] = [0,0] unless h.key? k h[k][0] += x h[k][1] -= x } puts "h.inspect = #{h.inspect}" puts "h.keys = #{h.keys.inspect}" puts "h.values = #{h.values.inspect}" d.each{|k| puts "#{k} = #{h[k].inspect}"} ----- ruby good1.rb h.inspect = {"a"=>[0, 0], "b"=>[1, -1], "c"=>[2, -2]} h.keys = ["a", "b", "c"] h.values = [[0, 0], [1, -1], [2, -2]] a = [0, 0] b = [1, -1] c = [2, -2] ---------------------------------------- http://redmine.ruby-lang.org/issues/show/2004 ---------------------------------------- http://redmine.ruby-lang.org