Class: Link
- Inherits:
-
Object
- Object
- Link
- Defined in:
- lib/rgraph/link.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(arg) ⇒ Link
constructor
A new instance of Link.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(arg) ⇒ Link
Returns a new instance of Link.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rgraph/link.rb', line 4 def initialize(arg) @args = arg @source = @args.delete(:source) @target = @args.delete(:target) @type = @args.delete(:type) || 'undirected' 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 @args[:weight] ||= 1 @source.neighbours << @target @target.neighbours << @source unless @type == 'directed' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
21 22 23 24 |
# File 'lib/rgraph/link.rb', line 21 def method_missing(name, *args) super unless args.empty? @args[name] end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
2 3 4 |
# File 'lib/rgraph/link.rb', line 2 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
2 3 4 |
# File 'lib/rgraph/link.rb', line 2 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
2 3 4 |
# File 'lib/rgraph/link.rb', line 2 def type @type end |