0

我有两个二级哈希,我必须合并两个哈希

hash1 = {"brands"=>{"likes"=>["gucci", "ck", "armani", "heyo"], "dislikes"=>["lv", "tods", "pols"]}}

hash2 = {"brands"=>{"likes"=>["bampam","plot"], "dislikes"=>["pom", "ui"]}}

输出应该是

 hash1 = {"brands"=>{"likes"=>["gucci", "ck", "armani", "heyo","bampam","plot"], "dislikes"=>["lv", "tods", "pols","pom","ui"]}}

我试过这段代码

hash1.merge!(hash2) { |k, o, n| o + n }

但这适用于一级哈希,不适用于二级哈希,哈希内的哈希

4

0 回答 0