0

誰かが理由を知っていますか

hash['City'] = {}
hash['City']['answer0'] = 'foo'

次のエラーが発生します。

undefined method `+@' for {"answer0"=>"foo"}:Hash

ありがとう

4

1 に答える 1

2

If you want to have 'multi-dimentional' hashes you need to properly define the hash like so:

a = Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }

Then you can do:

a['city']['answer0'] = 'foo'
于 2013-03-11T22:01:08.720 に答える