class Connected::GenericNode
Generic example node
Attributes
connections[RW]
name[R]
Public Class Methods
new(name)
click to toggle source
# File lib/connected/generic_node.rb, line 11 def initialize(name) @name = name @connections = [] end
Public Instance Methods
connects_to(other, metric: 1, state: :open, directed: false)
click to toggle source
# File lib/connected/generic_node.rb, line 16 def connects_to(other, metric: 1, state: :open, directed: false) # Only one connection between nodes return true if neighbors.include?(other) connections << GenericConnection.new( from: self, to: other, metric: metric, state: state.to_sym ) other.connects_to(self, metric: metric, state: state) unless directed end
disconnect_from(other, directed: false)
click to toggle source
# File lib/connected/generic_node.rb, line 27 def disconnect_from(other, directed: false) connections.delete_if { |c| c.to == other } other.disconnect_from(self) if other.neighbors.include?(self) && !directed end