Created
May 25, 2012 15:21
-
-
Save AJFaraday/2788740 to your computer and use it in GitHub Desktop.
<pride />
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
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