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
A new instance of NodeArray.
-
#push(n) ⇒ Object
Add the given node at the end of the list.
-
#set_default(dict) ⇒ Object
Set some default values for current elements.
Constructor Details
Instance Method Details
#push(n) ⇒ Object
Add the given node at the end of the list
134 135 136 137 138 139 140 141 142 |
# File 'lib/graph.rb', line 134 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) ⇒ Object
Note:
This method can be called multiple times.
Set some default values for current elements.
127 128 129 130 |
# File 'lib/graph.rb', line 127 def set_default(dict) @defaults.update(dict) self.map! { |e| e.update(@defaults) } end |