Module: DataMapper::Is::Tree::InstanceMethods
- Defined in:
- lib/dm_is_a_tree.rb
Instance Method Summary collapse
-
#ancestors ⇒ Object
Returns list of ancestors, starting with the root.
-
#generation ⇒ Object
(also: #self_and_siblings)
Returns all children of the current node’s parent.
-
#root ⇒ Object
grandchild1.root # => root.
-
#siblings ⇒ Object
Returns all siblings of the current node.
Instance Method Details
#ancestors ⇒ Object
Returns list of ancestors, starting with the root.
grandchild1.ancestors # => [root, child]
88 89 90 91 92 |
# File 'lib/dm_is_a_tree.rb', line 88 def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes.reverse end |
#generation ⇒ Object Also known as: self_and_siblings
Returns all children of the current node’s parent.
grandchild1.generation # => [grandchild1, grandchild2]
113 114 115 |
# File 'lib/dm_is_a_tree.rb', line 113 def generation parent ? parent.children : self.class.roots end |
#root ⇒ Object
grandchild1.root # => root
97 98 99 100 101 |
# File 'lib/dm_is_a_tree.rb', line 97 def root node = self node = node.parent while node.parent node end |
#siblings ⇒ Object
Returns all siblings of the current node.
grandchild1.siblings # => [grandchild2]
106 107 108 |
# File 'lib/dm_is_a_tree.rb', line 106 def siblings generation - [self] end |