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.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/graph.rb', line 122 def initialize name = nil, graph = nil, &block @name = name @graph = graph graph << self if graph @nodes = Hash.new { |h,k| h[k] = Node.new self, k } @edges = Hash.new { |h,k| h[k] = Hash.new { |h2, 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 |