def ancestors
ancestors = []
x = parent
while x
ancestors << x
x = x.parent
end
ancestors.reverse
end
Refactorings
No refactoring yet !
Aaron Tinio
February 21, 2011, February 21, 2011 02:24, permalink
modified from thinking-sphinx:
def ancestors_with_self (parent ? parent.ancestors_with_self : []) << self end def ancestors ancestors[0..-2] end
Aaron Tinio
February 21, 2011, February 21, 2011 02:27, permalink
ooops! this is the correct one:
def ancestors_with_self (parent ? parent.ancestors_with_self : []) << self end def ancestors ancestors_with_self[0..-2] end
Is there a one-liner to replace this with?