Last active
August 29, 2015 14:02
-
-
Save jasonm23/c08385b93ddcc6b466a3 to your computer and use it in GitHub Desktop.
Recursive hash compact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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