Module: ActsAsTree::InstanceMethods
- Defined in:
- lib/acts_as_tree.rb
Instance Method Summary collapse
-
#ancestors ⇒ Object
Returns list of ancestors, starting from parent until root.
-
#root ⇒ Object
Returns the root node of the tree.
-
#self_and_children ⇒ Object
Returns children (without subchildren) and current node itself.
-
#self_and_siblings ⇒ Object
Returns all siblings and a reference to the current node.
-
#siblings ⇒ Object
Returns all siblings of the current node.
Instance Method Details
#ancestors ⇒ Object
Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
123 124 125 126 127 |
# File 'lib/acts_as_tree.rb', line 123 def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes end |
#root ⇒ Object
Returns the root node of the tree.
130 131 132 133 134 |
# File 'lib/acts_as_tree.rb', line 130 def root node = self node = node.parent while node.parent node end |
#self_and_children ⇒ Object
Returns children (without subchildren) and current node itself.
root.self_and_children # => [root, child1]
153 154 155 |
# File 'lib/acts_as_tree.rb', line 153 def self_and_children [self] + self.children end |
#self_and_siblings ⇒ Object
Returns all siblings and a reference to the current node.
subchild1.self_and_siblings # => [subchild1, subchild2]
146 147 148 |
# File 'lib/acts_as_tree.rb', line 146 def self_and_siblings parent ? parent.children : self.class.roots end |
#siblings ⇒ Object
Returns all siblings of the current node.
subchild1.siblings # => [subchild2]
139 140 141 |
# File 'lib/acts_as_tree.rb', line 139 def siblings self_and_siblings - [self] end |