我想构建一个嵌套的哈希数组。我有一个数组,branch
看起来像这样:
branch = ["handbags", "womens-shoes", "womens-beauty", "womens-clothes"]
然后我有另一个数组,其中包含以下内容handbags
:
handbags = ["wallets", "backpacks", "clutches", "evening-handbags", "hobo-bags", "satchels", "shoulder-bags", "tote-bags"]
我想在一个循环中将handbags
数组插入到branch
数组中,这样我就得到了这样的东西:
branch = {"handbags" => ["wallets", "backpacks", "clutches", "evening-handbags", "hobo-bags", "satchels", "shoulder-bags", "tote-bags"], "womens-shoes"],...}
我这样尝试:
def insert_branch(branch, branch_index, candidate, candidate_index)
branch[[branch_index], branch[branch_index]] ||= {}
branch[[branch_index], branch[branch_index]] = candidate[candidate_index]
end
在哪里
candidate[candidate_index] = ["wallets", "backpacks", "clutches", "evening-handbags", "hobo-bags", "satchels", "shoulder-bags", "tote-bags"]
给我
无法将数组转换为整数
我怎样才能做到这一点?