ハッシュのネストされた配列を作成したいと思います。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"]
私にくれます
配列を整数に変換できません
どうすればこれを達成できますか?