Methods
Public Instance methods
ancestors()

Returns list of ancestors, starting from parent until root.

  subchild1.ancestors # => [child1, root]
    # 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
root()

Returns the root node of the tree.

    # 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
self_and_siblings()

Returns all siblings and a reference to the current node.

  subchild1.self_and_siblings # => [subchild1, subchild2]
    # 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
siblings()

Returns all siblings of the current node.

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