我有两个二级散列,并且我必须合并两个散列
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 }
但这适用于1级哈希,不适用于2级哈希,哈希内部的哈希