Module ActiveRecord::Acts::Tree::InstanceMethods
In: vendor/rails/activerecord/lib/active_record/acts/tree.rb

Methods

Public Instance methods

Returns list of ancestors, starting from parent until root.

  subchild1.ancestors # => [child1, root]

[Source]

    # File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 68
68:         def ancestors
69:           node, nodes = self, []
70:           nodes << node = node.parent while node.parent
71:           nodes
72:         end

Returns the root node of the tree.

[Source]

    # File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 75
75:         def root
76:           node = self
77:           node = node.parent while node.parent
78:           node
79:         end

Returns all siblings and a reference to the current node.

  subchild1.self_and_siblings # => [subchild1, subchild2]

[Source]

    # File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 91
91:         def self_and_siblings
92:           parent ? parent.children : self.class.roots
93:         end

Returns all siblings of the current node.

  subchild1.siblings # => [subchild2]

[Source]

    # File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 84
84:         def siblings
85:           self_and_siblings - [self]
86:         end

[Validate]