Class: Graphsrb::Vertex
- Inherits:
-
Object
- Object
- Graphsrb::Vertex
- Defined in:
- lib/graphsrb/vertex.rb
Overview
This class represents a graph vertex.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #!=(vertex) ⇒ Object
-
#==(vertex) ⇒ Object
Compares two vertices.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(id) ⇒ Vertex
constructor
Creates a vertex given its
id, a nonnegative integer. - #to_s ⇒ Object
Constructor Details
#initialize(id) ⇒ Vertex
Creates a vertex given its id, a nonnegative integer.
7 8 9 10 |
# File 'lib/graphsrb/vertex.rb', line 7 def initialize(id) raise Graphsrb::VertexInitializationError, 'Vertex id may not be nil' if id.nil? @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/graphsrb/vertex.rb', line 4 def id @id end |
Instance Method Details
#!=(vertex) ⇒ Object
17 18 19 |
# File 'lib/graphsrb/vertex.rb', line 17 def !=(vertex) id != vertex.id end |
#==(vertex) ⇒ Object
Compares two vertices. Two vertices are equal if their ids are equal.
13 14 15 |
# File 'lib/graphsrb/vertex.rb', line 13 def ==(vertex) id == vertex.id end |
#eql?(other) ⇒ Boolean
21 22 23 |
# File 'lib/graphsrb/vertex.rb', line 21 def eql?(other) self == other end |
#hash ⇒ Object
29 30 31 |
# File 'lib/graphsrb/vertex.rb', line 29 def hash self.id end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/graphsrb/vertex.rb', line 25 def to_s self.id.to_s end |