class Link #attr_accessor :source, :target def initialize(arg) @args = arg if @args[:source] == nil raise Exception.new("source cant be nil") end if @args[:target] == nil raise Exception.new("target cant be nil") end if not @args[:source].is_a? Node raise Exception.new("source must be of type Node") end if not @args[:target].is_a? Node raise Exception.new("target must be of type Node") end @args[:weight] ||= 1 @args[:source].neighbours << @args[:target] @args[:target].neighbours << @args[:source] end def method_missing(name, *args) super unless args.empty? @args[name] end end