我有这样的代码:为什么不是这个Ruby哈希我认为它会是什么?
$ze = Hash.new(Hash.new(2))
$ze['test'] = {0=> 'a', 1=>'b', 3 => 'c'}
$ze[5][0] = 'one'
$ze[5][1] = "two"
puts $ze
puts $ze[5]
这是输出:
{"test"=>{0=>"a", 1=>"b", 3=>"c"}}
{0=>"one", 1=>"two"}
为什么不是输出:
{"test"=>{0=>"a", 1=>"b", 3=>"c"}, 5=>{0=>"one", 1=>"two"}}
{0=>"one", 1=>"two"}
?
不要使用全局变量,它们是丑陋! – Hauleth