Skip to content

Instantly share code, notes, and snippets.

@cfcosta
Created January 6, 2012 16:52
Show Gist options
  • Save cfcosta/1571397 to your computer and use it in GitHub Desktop.
Save cfcosta/1571397 to your computer and use it in GitHub Desktop.
# 1.8
hash = {:foo => {:bar => {:baz => [1,2,3]}}}
to_hash = lambda { |k,v| v.is_a?(Hash) ? [k, v.map(&to_hash)] : [k,v] }
p hash.map(&to_hash)
# 1.9
hash = {:foo => {:bar => {:baz => [1,2,3]}}}
to_hash = lambda { |el| el[1].is_a?(Hash) ? [el[0], el[1].map(&to_hash)] : el }
p hash.map(&to_hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment