Class: MiniGraph::Core::Edge::Directed
- Inherits:
-
Object
- Object
- MiniGraph::Core::Edge::Directed
- Defined in:
- lib/mini_graph/core/edge.rb
Overview
Directed Edge
Direct Known Subclasses
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
Instance Method Summary collapse
-
#==(edge) ⇒ Object
cannot use alias or alias_method for this, as subclasses (e.g. UndirectedEdge) do not behave as expected.
- #eql?(edge) ⇒ Boolean
-
#initialize(origin, destination) ⇒ Directed
constructor
A new instance of Directed.
-
#inspect ⇒ Object
Another case of not using alias to allow subclasses to behave as expected.
-
#reverse ⇒ Object
Reverses the direction of the edge.
-
#self_loop? ⇒ Boolean
Indicates a self-looping edge; i.e., an edge that connects a vertex to itself.
- #to_s ⇒ Object
Constructor Details
#initialize(origin, destination) ⇒ Directed
Returns a new instance of Directed.
14 15 16 17 |
# File 'lib/mini_graph/core/edge.rb', line 14 def initialize(origin, destination) @origin = origin @destination = destination end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
12 13 14 |
# File 'lib/mini_graph/core/edge.rb', line 12 def destination @destination end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
12 13 14 |
# File 'lib/mini_graph/core/edge.rb', line 12 def origin @origin end |
Instance Method Details
#==(edge) ⇒ Object
cannot use alias or alias_method for this, as subclasses (e.g. UndirectedEdge) do not behave as expected. We’ll be explicit.
25 26 27 |
# File 'lib/mini_graph/core/edge.rb', line 25 def ==(edge) eql?(edge) end |
#eql?(edge) ⇒ Boolean
19 20 21 |
# File 'lib/mini_graph/core/edge.rb', line 19 def eql?(edge) origin == edge.origin && destination == edge.destination end |
#inspect ⇒ Object
Another case of not using alias to allow subclasses to behave as expected.
34 35 36 |
# File 'lib/mini_graph/core/edge.rb', line 34 def inspect to_s end |
#reverse ⇒ Object
Reverses the direction of the edge
39 40 41 |
# File 'lib/mini_graph/core/edge.rb', line 39 def reverse self.class.new(destination, origin) end |
#self_loop? ⇒ Boolean
Indicates a self-looping edge; i.e., an edge that connects a vertex to itself.
45 46 47 |
# File 'lib/mini_graph/core/edge.rb', line 45 def self_loop? origin == destination end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/mini_graph/core/edge.rb', line 29 def to_s "(#{origin} -> #{destination})" end |