Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
[Source]
# File lib/sequel/plugins/tree.rb, line 81 81: def ancestors 82: node, nodes = self, [] 83: nodes << node = node.parent while node.parent 84: nodes 85: end
# File lib/sequel/plugins/tree.rb, line 90 90: def descendants 91: nodes = self.children.dup 92: nodes.each{|child| nodes.concat(child.descendants)} 93: nodes 94: 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 98 98: def root 99: ancestors.last || self 100: end
Returns all siblings and a reference to the current node.
subchild1.self_and_siblings # => [subchild1, subchild2]
# File lib/sequel/plugins/tree.rb, line 105 105: def self_and_siblings 106: parent ? parent.children : model.roots 107: end
Returns all siblings of the current node.
subchild1.siblings # => [subchild2]
# File lib/sequel/plugins/tree.rb, line 112 112: def siblings 113: self_and_siblings - [self] 114: end
[Validate]