class MiniGraph::Core::Edge::Directed
Attributes
destination[R]
origin[R]
Public Class Methods
new(origin, destination)
click to toggle source
# File lib/mini_graph/core/edge.rb, line 14 def initialize(origin, destination) @origin = origin @destination = destination end
Public Instance Methods
==(edge)
click to toggle source
cannot use alias or alias_method for this, as subclasses (e.g. UndirectedEdge) do not behave as expected. We'll be explicit.
# File lib/mini_graph/core/edge.rb, line 25 def ==(edge) eql?(edge) end
eql?(edge)
click to toggle source
# File lib/mini_graph/core/edge.rb, line 19 def eql?(edge) origin == edge.origin && destination == edge.destination end
inspect()
click to toggle source
Another case of not using alias to allow subclasses to behave as expected.
# File lib/mini_graph/core/edge.rb, line 34 def inspect to_s end
reverse()
click to toggle source
Reverses the direction of the edge
# File lib/mini_graph/core/edge.rb, line 39 def reverse self.class.new(destination, origin) end
self_loop?()
click to toggle source
Indicates a self-looping edge; i.e., an edge that connects a vertex to itself.
# File lib/mini_graph/core/edge.rb, line 45 def self_loop? origin == destination end
to_s()
click to toggle source
# File lib/mini_graph/core/edge.rb, line 29 def to_s "(#{origin} -> #{destination})" end