Skip to content

Instantly share code, notes, and snippets.

@DNNX DNNX/leaves.rb
Created Aug 22, 2011

Embed
What would you like to do?
class Hash
# {'x'=>{'y'=>{'z'=>1,'a'=>2}}}.leaves == [1,2]
def leaves
each_value.flat_map do |value|
value.respond_to?(:leaves) ? value.leaves : [value]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.