Class: Foobara::Util::Tree
- Defined in:
- foobara-util-0.0.11/lib/foobara/util/tree.rb
Instance Attribute Summary
Attributes inherited from SubTree
#parent_tree, #to_parent, #value
Instance Method Summary collapse
-
#initialize(data, to_parent = nil) ⇒ Tree
constructor
A new instance of Tree.
- #to_s(to_name = nil, &block) ⇒ Object
Methods inherited from SubTree
#add, #children_trees, #include?, #node_for, #root?
Constructor Details
#initialize(data, to_parent = nil) ⇒ Tree
Returns a new instance of Tree.
105 106 107 108 109 110 111 |
# File 'foobara-util-0.0.11/lib/foobara/util/tree.rb', line 105 def initialize(data, to_parent = nil, &) super(nil, to_parent, &) data.each do |object| add(object) end end |
Instance Method Details
#to_s(to_name = nil, &block) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'foobara-util-0.0.11/lib/foobara/util/tree.rb', line 113 def to_s(to_name = nil, &block) to_name = if to_name to_name.to_proc elsif block_given? block else :to_s.to_proc end children_trees.map { |child| child.to_s(to_name) }.join("\n") end |