Class: Graphsrb::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/graphsrb/vertex.rb

Overview

This class represents a graph vertex.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (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

Returns:

  • (Boolean)


21
22
23
# File 'lib/graphsrb/vertex.rb', line 21

def eql?(other)
  self == other
end

#hashObject



29
30
31
# File 'lib/graphsrb/vertex.rb', line 29

def hash
  self.id
end

#to_sObject



25
26
27
# File 'lib/graphsrb/vertex.rb', line 25

def to_s
  self.id.to_s
end