我需要使用數組當前迭代的名稱創建字典的名稱。使用部分變量名創建字典名稱
例如:
sites = ["google", "facebook", "twitter", "stackoverflow"]
sites.each do |site|
#{site}_success_hash = {} <-- I need the correct syntax for achieving this result.
... populate ... hash
end
所以我希望4個哈希值,命名爲google_success_hash
等
我不知道這一點,它的駕駛我瘋了。
您應該將您的字典存儲在超級字典中,而不是製作多個全球級別的字典。 – 2013-02-09 23:18:49
同意;它到目前爲止只是哈希散列。 – 2013-02-09 23:23:47