Created
January 30, 2009 14:12
-
-
Save gravis/55081 to your computer and use it in GitHub Desktop.
Convert keys and values to int (to_i) for a Hash
This file contains 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
# convert a hash composed of strings to integers | |
# ex: h = {"1" => "2", "3" => "4"} | |
# I want {1 => 2, 3 => 4} | |
string_hash = {"1" => "2", "3" => "4"} | |
# => {"1"=>"2", "3"=>"4"} | |
int_hash = Hash[*string_hash.to_a.flatten.map(&:to_i)] | |
# => {1=>2, 3=>4} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment