Created
October 15, 2015 20:04
-
-
Save liaden/dfe5e02a7f7856faf5ef to your computer and use it in GitHub Desktop.
This file contains 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
h1 = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }.with_indifferent_access | |
h2 = h1.dup | |
h1['x']['y']['a'] = 5 | |
h1['x']['y']['arr'] = [1,2,3] | |
h2['x']['y']['arr'] = [2,3,4] | |
h1['h'] = [1,2] | |
h2['f'] = [3,4] | |
h1.deep_merge!(h2) { |key, old_value, new_value| (Array(old_value) + Array(new_value)).uniq } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment