Ruby Hash Weirdness。有人能告诉我这里发生了什么吗?

时间:2016-01-27 16:58:06

标签: ruby hash

在创建了一些新的哈希值之后,我发现了这个Ruby怪异的东西......任何人都可以解释发生了什么吗?

irb(main):001:0> some_hash = Hash.new({})
=> {}
irb(main):002:0> some_hash[:foo][:bar] = :baz
=> :baz
irb(main):003:0> some_hash
=> {}
irb(main):004:0> some_hash.keys
=> []
irb(main):005:0> some_hash[:foo]
=> {:bar=>:baz}
irb(main):006:0> some_hash.size
=> 0
irb(main):007:0> some_hash[:some_completely_new_key]
=> {:bar=>:baz}

0 个答案:

没有答案