Skip to content

Instantly share code, notes, and snippets.

@Aeramor
Created January 24, 2014 22:10
Show Gist options
  • Save Aeramor/8607769 to your computer and use it in GitHub Desktop.
Save Aeramor/8607769 to your computer and use it in GitHub Desktop.
Ruby change keys of a hash with a hash map.
ages = { "Bruce" => 32, "Clark" => 28 }
mappings = {"Bruce" => "Bruce Wayne", "Clark" => "Clark Kent"}
Hash[ages.map {|k, v| [mappings[k], v] }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment