Module: ActiveRecord::Acts::Tree::InstanceMethods
- Defined in:
- lib/active_record/acts/tree.rb
Instance Method Summary collapse
-
#ancestors ⇒ Object
Returns list of ancestors, starting from parent until root.
- #root ⇒ Object
- #self_and_siblings ⇒ Object
- #siblings ⇒ Object
Instance Method Details
#ancestors ⇒ Object
Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
67 68 69 70 71 |
# File 'lib/active_record/acts/tree.rb', line 67 def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes end |
#root ⇒ Object
73 74 75 76 77 |
# File 'lib/active_record/acts/tree.rb', line 73 def root node = self node = node.parent while node.parent node end |
#self_and_siblings ⇒ Object
83 84 85 |
# File 'lib/active_record/acts/tree.rb', line 83 def self_and_siblings parent ? parent.children : self.class.roots end |
#siblings ⇒ Object
79 80 81 |
# File 'lib/active_record/acts/tree.rb', line 79 def siblings self_and_siblings - [self] end |