Skip to content

Instantly share code, notes, and snippets.

@liaden
Created October 15, 2015 20:04
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 liaden/dfe5e02a7f7856faf5ef to your computer and use it in GitHub Desktop.
Save liaden/dfe5e02a7f7856faf5ef to your computer and use it in GitHub Desktop.
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