Class: CyclicLink

Inherits:
Object
  • Object
show all
Defined in:
lib/cpp_dependency_graph/cyclic_link.rb

Overview

Represents a cyclic link betwee two nodes, it is special in the sense it is designed to be used as a key in a hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_a, node_b) ⇒ CyclicLink



10
11
12
13
# File 'lib/cpp_dependency_graph/cyclic_link.rb', line 10

def initialize(node_a, node_b)
  @node_a = node_a
  @node_b = node_b
end

Instance Attribute Details

#node_aObject (readonly)

Returns the value of attribute node_a.



7
8
9
# File 'lib/cpp_dependency_graph/cyclic_link.rb', line 7

def node_a
  @node_a
end

#node_bObject (readonly)

Returns the value of attribute node_b.



8
9
10
# File 'lib/cpp_dependency_graph/cyclic_link.rb', line 8

def node_b
  @node_b
end

Instance Method Details

#eql?(other) ⇒ Boolean



15
16
17
18
# File 'lib/cpp_dependency_graph/cyclic_link.rb', line 15

def eql?(other)
  (@node_a == other.node_a && @node_b == other.node_b) ||
    (@node_a == other.node_b && @node_b == other.node_a)
end

#hashObject



20
21
22
# File 'lib/cpp_dependency_graph/cyclic_link.rb', line 20

def hash
  [@node_a, @node_b].to_set.hash
end

#to_sObject



24
25
26
# File 'lib/cpp_dependency_graph/cyclic_link.rb', line 24

def to_s
  "#{node_a} <-> #{node_b}"
end