class Creq::TreeNode
Attributes
items[R]
parent[R]
Public Class Methods
new()
click to toggle source
# File lib/creq/tree_node.rb, line 11 def initialize @items = [] @parent = nil end
Public Instance Methods
<<(node)
click to toggle source
# File lib/creq/tree_node.rb, line 16 def <<(node) node.parent = self @items << node node end
each() { |self| ... }
click to toggle source
# File lib/creq/tree_node.rb, line 22 def each(&block) return unless block_given? yield(self) @items.each { |node| node.each(&block) } end
level()
click to toggle source
# File lib/creq/tree_node.rb, line 28 def level return 1 if @parent.nil? @parent.level + 1 end
root()
click to toggle source
# File lib/creq/tree_node.rb, line 37 def root pa = self pa = pa.parent while pa.parent pa end
root?()
click to toggle source
# File lib/creq/tree_node.rb, line 33 def root? @parent.nil? end
Protected Instance Methods
parent=(node)
click to toggle source
# File lib/creq/tree_node.rb, line 45 def parent=(node) @parent = node end