Created
November 11, 2012 09:02
-
-
Save maxim/4054223 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
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