Skip to content

Instantly share code, notes, and snippets.

@jvkumar

jvkumar/gist:4543602

Created Jan 16, 2013
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@jvkumar 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