Method: Graph#initialize
- Defined in:
- lib/graph.rb
#initialize(name = nil, graph = nil, &block) ⇒ Graph
Creates a new graph object. Optional name and parent graph are available. Also takes an optional block for DSL-like use.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/graph.rb', line 137 def initialize name = nil, graph = nil, &block @name = name @graph = graph graph << self if graph @nodes_order = [] @nodes = Hash.new { |h,k| @nodes_order << k; h[k] = Node.new self, k } @edges_order = [] @edges = Hash.new { |h,k| h[k] = Hash.new { |h2, k2| @edges_order << [k, k2] h2[k2] = Edge.new self, self[k], self[k2] } } @graph_attribs = [] @node_attribs = [] @edge_attribs = [] @subgraphs = [] self.scheme = graph.scheme if graph node_attribs << scheme if scheme instance_eval(&block) if block end |