Answers for "ruby merge 2 hashes"

3

ruby merge array of hashes into one hash

a.reduce Hash.new, :merge
Posted by: Guest on July-31-2020
2

ruby hash merge

h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge(h2)   #=> {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
               #=> {"a"=>100, "b"=>54,  "c"=>300}
h1             #=> {"a"=>100, "b"=>200}
Posted by: Guest on May-06-2020

Browse Popular Code Answers by Language