Skip to content

Instantly share code, notes, and snippets.

@dtolj
Created August 4, 2011 17:57
Show Gist options
  • Save dtolj/1125771 to your computer and use it in GitHub Desktop.
Save dtolj/1125771 to your computer and use it in GitHub Desktop.
def classify(o)
case o
when Hash
h = {}
o.each {|k,v| h[k] = classify(v)}
h
else
o.class
end
end
p classify({'en' => {'A' => 1, 'B' => {'C' => 3, 'D' => 'four'}}})
Output:
{"en"=>{"A"=>Fixnum, "B"=>{"C"=>Fixnum, "D"=>String}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment