Skip to content

Instantly share code, notes, and snippets.

@maxim
Created November 11, 2012 09:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxim/4054223 to your computer and use it in GitHub Desktop.
Save maxim/4054223 to your computer and use it in GitHub Desktop.
a = { foo: 'foo', bar: 'bar' }
b = { foo: 'fooo' }
# Reconcile duplicate keys
a.merge(b) {|k, old_v, new_v| [old_v, new_v].min}
# => { foo: 'foo', bar: 'bar' }
# Ever wanted Hash#map to return a hash? This is a workaround
a.merge(a) {|k, v| v.upcase}
# => { foo: "FOO", bar: "BAR" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment