lib/rgraph/link.rb in rgraph-0.0.3 vs lib/rgraph/link.rb in rgraph-0.0.4

- old
+ new

@@ -1,29 +1,21 @@ class Link - #attr_accessor :source, :target + attr_accessor :source, :target def initialize(arg) @args = arg - if @args[:source] == nil - raise Exception.new("source cant be nil") - end + @source = @args.delete(:source) + @target = @args.delete(:target) - if @args[:target] == nil - raise Exception.new("target cant be nil") - end + raise Exception.new("source cant be nil") unless @source + raise Exception.new("target cant be nil") unless @target + raise Exception.new("source must be of type Node") unless @source.is_a? Node + raise Exception.new("target must be of type Node") unless @target.is_a? Node - 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] + @source.neighbours << @target + @target.neighbours << @source end def method_missing(name, *args) super unless args.empty? @args[name]