Skip to content

Instantly share code, notes, and snippets.

@jvkumar
Created January 16, 2013 00:42
Show Gist options
  • Save jvkumar/4543602 to your computer and use it in GitHub Desktop.
Save jvkumar/4543602 to your computer and use it in GitHub Desktop.
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
@jvkumar
Copy link
Author

jvkumar commented Jan 16, 2013

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 } }] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment