Skip to content

Instantly share code, notes, and snippets.

@DNNX
Created August 22, 2011 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DNNX/1162503 to your computer and use it in GitHub Desktop.
Save DNNX/1162503 to your computer and use it in GitHub Desktop.
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