Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
Created May 25, 2012 15:21
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 AJFaraday/2788740 to your computer and use it in GitHub Desktop.
Save AJFaraday/2788740 to your computer and use it in GitHub Desktop.
<pride />
def descendant_leaves
result = []
result << children
until result.flatten!.all?{|x| x.leaf?}
result.each do |location|
unless location.leaf?
result << location.children
result.delete(location)
end
end
end
result << self if leaf?
result
end
def leaf?
children.empty?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment