Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
# File lib/sequel/plugins/tree.rb, line 85 def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes end
Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
# File lib/sequel/plugins/tree.rb, line 94 def descendants nodes = children.dup nodes.each{|child| nodes.concat(child.descendants)} nodes end
Returns the root node of the tree that this node descends from. This node is returned if it is a root node itself.
# File lib/sequel/plugins/tree.rb, line 102 def root ancestors.last || self end
Returns true if this is a root node, false otherwise.
# File lib/sequel/plugins/tree.rb, line 107 def root? !new? && self[model.parent_column].nil? end
Generated with the Darkfish Rdoc Generator 2.