Class: Graph::NodeArray
- Inherits:
-
Array
- Object
- Array
- Graph::NodeArray
- Defined in:
- lib/graph.rb
Overview
An array of Node objects
Instance Method Summary collapse
-
#initialize(li) ⇒ NodeArray
constructor
Create a new
NodeArray
from an existingArray
. -
#push(n) ⇒ NodeArray
Add the given node at the end of the list.
-
#set_default(dict) ⇒ NodeArray
Set some default values for current elements.
Constructor Details
Instance Method Details
#push(n) ⇒ NodeArray
Add the given node at the end of the list
152 153 154 155 156 157 158 159 160 |
# File 'lib/graph.rb', line 152 def push(n) if (!n.is_a?(Hash) && !n.is_a?(Node)) raise TypeError.new "#{n.inspect} is not an Hash nor a Node!" end n = Node.new(n) if (n.is_a?(Hash)) super(n.clone.update(@defaults)) end |
#set_default(dict) ⇒ NodeArray
Note:
This method can be called multiple times.
Set some default values for current elements.
144 145 146 147 |
# File 'lib/graph.rb', line 144 def set_default(dict) @defaults.update(dict) self.map! { |e| e.update(@defaults) } end |