Class: Tangle::Edge
- Inherits:
-
Object
- Object
- Tangle::Edge
- Includes:
- Mixin::Initialize
- Defined in:
- lib/tangle/edge.rb
Overview
An edge in a graph, connecting two vertices
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from Mixin::Initialize
Instance Method Summary collapse
- #[](from_vertex) ⇒ Object
- #each_vertex(&block) ⇒ Object
- #include?(vertex) ⇒ Boolean
-
#initialize(vertex1, vertex2 = vertex1, name: nil, **kwargs) ⇒ Edge
constructor
Create a new edge between vertices.
- #loop? ⇒ Boolean
- #to_s ⇒ Object (also: #inspect)
- #walk(from_vertex) ⇒ Object
Constructor Details
#initialize(vertex1, vertex2 = vertex1, name: nil, **kwargs) ⇒ Edge
Create a new edge between vertices
Edge.new(vtx1) => Edge (loop) Edge.new(vtx1, vtx2) => Edge
End users should probably use Graph#add_edge instead.
20 21 22 23 24 |
# File 'lib/tangle/edge.rb', line 20 def initialize(vertex1, vertex2 = vertex1, name: nil, **kwargs) @name = name initialize_vertices(vertex1, vertex2) initialize_mixins(**kwargs) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/tangle/edge.rb', line 11 def name @name end |
Instance Method Details
#[](from_vertex) ⇒ Object
26 27 28 |
# File 'lib/tangle/edge.rb', line 26 def [](from_vertex) @vertices[from_vertex] end |
#each_vertex(&block) ⇒ Object
40 41 42 |
# File 'lib/tangle/edge.rb', line 40 def each_vertex(&block) @vertices.each_key(&block) end |
#include?(vertex) ⇒ Boolean
44 45 46 |
# File 'lib/tangle/edge.rb', line 44 def include?(vertex) each_vertex.include?(vertex) end |
#loop? ⇒ Boolean
48 49 50 |
# File 'lib/tangle/edge.rb', line 48 def loop? @loop end |
#to_s ⇒ Object Also known as: inspect
34 35 36 37 |
# File 'lib/tangle/edge.rb', line 34 def to_s vertex1, vertex2 = @vertices.keys "{#{vertex1}<->#{vertex2}}" end |
#walk(from_vertex) ⇒ Object
30 31 32 |
# File 'lib/tangle/edge.rb', line 30 def walk(from_vertex) @vertices.fetch(from_vertex) end |