Class: Puffer::Resource::Tree
- Inherits:
-
Object
- Object
- Puffer::Resource::Tree
- Defined in:
- lib/puffer/resource/tree.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Instance Method Summary collapse
- #append_node(*args) ⇒ Object
-
#initialize ⇒ Tree
constructor
A new instance of Tree.
- #method_missing(method, *args, &block) ⇒ Object
- #roots ⇒ Object
Constructor Details
#initialize ⇒ Tree
Returns a new instance of Tree.
6 7 8 |
# File 'lib/puffer/resource/tree.rb', line 6 def initialize @nodes = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
31 32 33 |
# File 'lib/puffer/resource/tree.rb', line 31 def method_missing method, *args, &block nodes.send method, *args, &block if nodes.respond_to? method end |
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
4 5 6 |
# File 'lib/puffer/resource/tree.rb', line 4 def nodes @nodes end |
Instance Method Details
#append_node(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puffer/resource/tree.rb', line 10 def append_node *args = args. parent = args.first parent = case parent when Integer then nodes[parent] when Puffer::Resource::Node, nil then parent else return end push Puffer::Resource::Node.new(parent, ) size.pred end |
#roots ⇒ Object
27 28 29 |
# File 'lib/puffer/resource/tree.rb', line 27 def roots nodes.select &:root? end |