1da5297d1f74861b24ce417dc2ac6c0ff3181111
[graph.njae.git] / lib / graph.njae / graph.rb
1 require 'ostruct'
2
3 # A simple graph library
4
5 module GraphNjae
6
7 # A container for all the parts of a graph. The graph can have arbitrary attributes,
8 # treated as method names.
9 class Graph < OpenStruct
10 def initialize
11 super
12 self.edges = Array.new
13 self.vertices = Array.new
14 self
15 end
16
17 # Add a Vertex or Edge to the graph.
18 def <<(other)
19 if other.class == Vertex
20 self.vertices << other
21 elsif
22 self.edges << other
23 end
24 self
25 end
26 end
27 end