#!/usr/local/bin/ruby class Graph attr :vertices attr :edges def initialize(vertices = [], edges = Hash.new {|h, k| h[k] = Hash.new {0} }) @vertices = vertices @edges = edges end end def grow(graph, a, b) c = c vertices = graph.vertices.dup edges = graph.edges.dup vertices << c edges[a][c] += 1 edges[c][b] += 1 Graph.new(vertices, edges) end g = Graph.new([0, 1]) p g p grow(g, 0, 1)