Created
January 16, 2013 00:42
-
-
Save jvkumar/4543602 to your computer and use it in GitHub Desktop.
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
def symbolize! | |
convertor = | |
lambda do |h| | |
if Hash === h | |
Hash[ | |
h.map do |k, v| | |
[k.respond_to?(:to_sym) ? k.to_sym : k, convertor[v]] | |
end | |
] | |
elsif Array === h | |
h.each {|e| | |
if (Hash === e) | |
Hash[ | |
e.map do |k, v| | |
[k.respond_to?(:to_sym) ? k.to_sym : k, convertor[v]] | |
end | |
] | |
# else | |
# convertor[e] | |
end | |
} | |
else | |
h | |
end | |
end | |
convertor[self] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to convert this hash
{:total_rows => 187, :offset => 0, :rows => [{"id" => "eFSHxaxMXARAjHyhczqfYg", "key" => ["025F3E38-C78E-475F-B92B-58412A98BFAD", "root", 6179430 ], "value" => "b7f393beb384c1f33165a3675bb27a39", "doc" => {"count" => 22, "size" => 6179430 } }] }