Class: CrossLanguageSpotter::Pair

Inherits:
Object
  • Object
show all
Defined in:
lib/crosslanguagespotter/methods/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(a, b) ⇒ Pair

Returns a new instance of Pair.



8
9
10
11
12
13
14
15
16
# File 'lib/crosslanguagespotter/methods/context.rb', line 8

def initialize(a,b)
    raise "error" unless a.source.position(:absolute)
    raise "error" unless b.source.position(:absolute)
    if b.source.artifact(:absolute).filename < a.source.artifact(:absolute).filename
        @nodes = [b,a]
    else
        @nodes = [a,b]
    end
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
# File 'lib/crosslanguagespotter/methods/context.rb', line 35

def ==(other)
    self.eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/crosslanguagespotter/methods/context.rb', line 30

def eql?(other)
    return false unless other.is_a?(Pair)
    self.nodes[0]==other.nodes[0] && self.nodes[1]==other.nodes[1]
end

#firstObject



18
19
20
# File 'lib/crosslanguagespotter/methods/context.rb', line 18

def first
    nodes[0]
end

#hashObject



43
44
45
# File 'lib/crosslanguagespotter/methods/context.rb', line 43

def hash
    nodes[0].hash*3+nodes[1].hash
end

#nodesObject



26
27
28
# File 'lib/crosslanguagespotter/methods/context.rb', line 26

def nodes
    @nodes
end

#secondObject



22
23
24
# File 'lib/crosslanguagespotter/methods/context.rb', line 22

def second
    nodes[1]
end

#to_sObject



39
40
41
# File 'lib/crosslanguagespotter/methods/context.rb', line 39

def to_s
    "[#{nodes[0]} <-> #{nodes[1]}]"
end