Module | ActiveRecord::Acts::Tree::InstanceMethods |
In: |
vendor/rails/activerecord/lib/active_record/acts/tree.rb
|
Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
# File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 69 69: def ancestors 70: node, nodes = self, [] 71: nodes << node = node.parent until not node.has_parent? 72: nodes 73: end
# File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 75 75: def root 76: node = self 77: node = node.parent until not node.has_parent? 78: node 79: end
# File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 85 85: def self_and_siblings 86: has_parent? ? parent.children : self.class.roots 87: end