Created
June 2, 2017 02:42
-
-
Save Martin91/136a6300746b8de401cbc7b4accd95b6 to your computer and use it in GitHub Desktop.
ruby hashes addition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hash1 = {a: 100, b: [1, 2], c: "hello"} | |
hash2 = {a: 300, b: [3, 4, 5], c: " world", d: "fh"} | |
hash1.merge(hash2) { |key, val_f, val_r| val_f + val_r } | |
# => {:a=>400, :b=>[1, 2, 3, 4, 5], :c=>"hello world", :d=>"fh"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment