Class: Tree::TreeNode

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/forest.rb

Overview

Monkey patch

Instance Method Summary collapse

Instance Method Details

#children_sizeObject



144
145
146
# File 'lib/forest.rb', line 144

def children_size
  children.size
end


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/forest.rb', line 148

def print_tree(level = 0)
  if is_root?
    print "*"
  else
    print "|" unless parent.is_last_sibling?
    print(' ' * (level - 1) * 4)
    print(is_last_sibling? ? "+" : "|")
    print "---"
    print(has_children? ? "+" : ">")
  end
  
  puts " #{name} #{content}"
  
  children { |child| child.print_tree(level + 1)}
end