Created
November 5, 2015 13:35
-
-
Save charlypoly/9c1b44b1a196be99bcb0 to your computer and use it in GitHub Desktop.
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 | |
# {'x'=>{'y'=>{'z'=>1,'a'=>2}}}.leaves == [1,2] | |
def leaves | |
leaves = [] | |
each_value do |value| | |
if value.is_a?(Hash) | |
value.leaves.each{|l| leaves << l } | |
elsif value.is_a?(Array) | |
value.each{|l| leaves << l } | |
else | |
leaves << value | |
end | |
end | |
leaves | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment