Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonm23/c08385b93ddcc6b466a3 to your computer and use it in GitHub Desktop.
Save jasonm23/c08385b93ddcc6b466a3 to your computer and use it in GitHub Desktop.
Recursive hash compact
# Recursive hash compact
def compact hash
p = ->(k,v){ (v.kind_of?(Hash) and v.keys.length > 0) ? (v.delete_if(&p);false) : (v.nil? or (v.kind_of?(Hash) and v.keys.length == 0)) }
hash.delete_if(&p)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment