0
有人不知道为什么未定义的方法'@”在轨
hash['City'] = {}
hash['City']['answer0'] = 'foo'
收到以下错误:
undefined method `[email protected]' for {"answer0"=>"foo"}:Hash
感谢
有人不知道为什么未定义的方法'@”在轨
hash['City'] = {}
hash['City']['answer0'] = 'foo'
收到以下错误:
undefined method `[email protected]' for {"answer0"=>"foo"}:Hash
感谢
如果你想拥有‘多维’散列你需要像这样正确定义散列:
a = Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
然后你可以这样做:
a['city']['answer0'] = 'foo'
当你像'hash = {}'一样初始化散列时会发生什么? – 2013-03-11 17:15:49
您没有显示出错线 – 2013-03-11 17:16:21
您可以添加堆栈跟踪发生此错误的位置吗?这不是在这里的任务,而是在其他地方。 – tadman 2013-03-11 17:26:36