Skip to content

Instantly share code, notes, and snippets.

@drio
Created March 20, 2009 22:11
Show Gist options
  • Save drio/82609 to your computer and use it in GitHub Desktop.
Save drio/82609 to your computer and use it in GitHub Desktop.
# one 1_1 2_1 two 1_2 2_2
def foo(h1, h2)
tmp = Hash.new {|hash, key| hash[key] = "" }
h1.each {|k,v| tmp[k] << v }
h2.each {|k,v| tmp[k] << " " + v }
tmp
end
hash1 = { "one" => "1_1" , "two" => "1_2" }
hash2 = { "one" => "2_1" , "two" => "2_2" }
new_hash = foo(hash1, hash2)
new_hash.each {|k,v| puts "#{k}: #{v}"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment