Skip to content

Instantly share code, notes, and snippets.

@charlypoly
Created November 5, 2015 13:35
Show Gist options
  • Save charlypoly/9c1b44b1a196be99bcb0 to your computer and use it in GitHub Desktop.
Save charlypoly/9c1b44b1a196be99bcb0 to your computer and use it in GitHub Desktop.
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