Module: ActiveRecord::Acts::Tree::InstanceMethods
- Defined in:
- vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb
Instance Method Summary
-
- (Object) ancestors
Returns list of ancestors, starting from parent until root.
-
- (Object) descendants
Returns list of descendants.
-
- (Object) root
Returns the root node of the tree.
-
- (Object) self_and_descendants
Returns list of descendants and a reference to the current node.
-
- (Object) self_and_siblings
Returns all siblings and a reference to the current node.
-
- (Object) siblings
Returns all siblings of the current node.
Instance Method Details
- (Object) ancestors
Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
68 69 70 71 72 |
# File 'vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb', line 68 def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes end |
- (Object) descendants
Returns list of descendants.
root.descendants # => [child1, subchild1, subchild2]
77 78 79 |
# File 'vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb', line 77 def descendants children + children.collect(&:children).flatten end |
- (Object) root
Returns the root node of the tree.
89 90 91 92 93 |
# File 'vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb', line 89 def root node = self node = node.parent while node.parent node end |
- (Object) self_and_descendants
Returns list of descendants and a reference to the current node.
root.self_and_descendants # => [root, child1, subchild1, subchild2]
84 85 86 |
# File 'vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb', line 84 def self_and_descendants [self] + descendants end |
- (Object) self_and_siblings
Returns all siblings and a reference to the current node.
subchild1.self_and_siblings # => [subchild1, subchild2]
105 106 107 |
# File 'vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb', line 105 def self_and_siblings parent ? parent.children : self.class.roots end |
- (Object) siblings
Returns all siblings of the current node.
subchild1.siblings # => [subchild2]
98 99 100 |
# File 'vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb', line 98 def siblings self_and_siblings - [self] end |