Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created December 1, 2012 21:55
Show Gist options
  • Save michaelfeathers/4185398 to your computer and use it in GitHub Desktop.
Save michaelfeathers/4185398 to your computer and use it in GitHub Desktop.
Sometimes you just need to zip two hashes
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