Created
June 16, 2015 18:33
-
-
Save bitops/89bc0dde016076b5a3d1 to your computer and use it in GitHub Desktop.
Simple Ruby to extract nested values from a Hash
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
class Hash | |
def extract_nested_values(hsh=self) | |
return hsh unless hsh.respond_to?(:keys) | |
hsh.keys.map do |k| | |
extract_nested_values(hsh[k]) | |
end.flatten | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment