Created
December 1, 2012 21:55
-
-
Save michaelfeathers/4185398 to your computer and use it in GitHub Desktop.
Sometimes you just need to zip two hashes
This file contains hidden or 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
def zip_hash hash_a, hash_b, missing_element = nil | |
all_keys = (hash_a.keys + hash_b.keys).uniq | |
result = {} | |
all_keys.each do |key| | |
result[key] = [hash_a[key] || missing_element, hash_b[key] || missing_element] | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment