Skip to content

Instantly share code, notes, and snippets.

@asterion
Created June 15, 2017 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asterion/a7ddec3f9741d6005e255887003ef273 to your computer and use it in GitHub Desktop.
Save asterion/a7ddec3f9741d6005e255887003ef273 to your computer and use it in GitHub Desktop.
rellenar un hash en ruby
meses = {
"ENERO" => [0],
"FEBRERO" => [0],
"MARZO" => [0],
"ABRIL" => [0],
"MAYO" => [0],
"JUNIO" => [0],
"JULIO" => [0],
"AGOSTO" => [0],
"SEPTIEMBRE" => [0],
"OCTUBRE" => [0],
"NOVIEMBRE" => [0],
"DICIEMBRE" => [0]
}
foo = {
"UNIDAD" => ["UNIDAD"],
"ENERO" => ["23", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
"FEBRERO" => ["23", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
"MARZO" => ["34", "0", "0", "0", "0", "0", "0", "0", "0", "0"]
}
meses.each do |key, value|
unless foo.has_key?(key)
foo[key] = value
end
end
puts foo["DICIEMBRE"]
puts foo["ENERO"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment