Bu kodu vardır:Bu Ruby hash, neden olduğunu düşündüğüm şey değil?
$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]
Ve bu çıktısı şöyledir:
{"test"=>{0=>"a", 1=>"b", 3=>"c"}, 5=>{0=>"one", 1=>"two"}}
{0=>"one", 1=>"two"}
:
{"test"=>{0=>"a", 1=>"b", 3=>"c"}}
{0=>"one", 1=>"two"}
Neden çıktı değil mi? $ze[5][0] = xxx
ile
küresel değişkenleri kullanmayın, bunlar çirkin! – Hauleth