Skip to content

Instantly share code, notes, and snippets.

@Martin91
Created June 2, 2017 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Martin91/136a6300746b8de401cbc7b4accd95b6 to your computer and use it in GitHub Desktop.
Save Martin91/136a6300746b8de401cbc7b4accd95b6 to your computer and use it in GitHub Desktop.
ruby hashes addition
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