Merge nested hash without overwritting in Ruby
问题 After checking this Ruby convert array to nested hash and other sites I am not able to achieve the following convertion: I have this: {"a"=>"text"} {"b"=>{"x"=>"hola"}} {"b"=>{"y"=>"pto"} } and I want to obtain: {"a"=>text, b=>{"x" => "hola", "y" => "pto" } } Until now the code seems like this: tm =[[["a"],"text"],[["b","x"],"hola"],[["b","y"],"pto"]] q = {} tm.each do |l| q = l[0].reverse.inject(l[1]) { |p, n| { n => p } } i += 1 end I tried with merge , but it overwrites the keys!. I tried