Class: Topiary::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/topiary/graph.rb

Overview

Represents a Graph

Direct Known Subclasses

DirectedGraph

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes = []) ⇒ Graph

Returns a new instance of Graph.



6
7
8
# File 'lib/topiary/graph.rb', line 6

def initialize(nodes=[])
  @nodes = nodes
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



4
5
6
# File 'lib/topiary/graph.rb', line 4

def nodes
  @nodes
end

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
# File 'lib/topiary/graph.rb', line 10

def to_s
  ar = nodes.map(&:to_s)
  if ar.empty?
    "{ }"
  else
    "{ #{ar.join('; ')} }"
  end
end