Class: Pair

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/totally_lazy/pair.rb

Instance Method Summary collapse

Constructor Details

#initialize(first, second) ⇒ Pair

Returns a new instance of Pair.



19
20
21
22
# File 'lib/totally_lazy/pair.rb', line 19

def initialize(first, second)
  @first = -> { first }
  @second = -> { second }
end

Instance Method Details

#<=>(other) ⇒ Object



40
41
42
# File 'lib/totally_lazy/pair.rb', line 40

def <=>(other)
  (first <=> other.first) <=> (second <=> other.second)
end

#enumeratorObject



32
33
34
35
36
37
38
# File 'lib/totally_lazy/pair.rb', line 32

def enumerator
  Enumerator.new { |y|
    y << first
    y << second
    raise StopIteration.new
  }
end

#firstObject



24
25
26
# File 'lib/totally_lazy/pair.rb', line 24

def first
  @first.()
end

#secondObject



28
29
30
# File 'lib/totally_lazy/pair.rb', line 28

def second
  @second.()
end

#to_sObject



44
45
46
# File 'lib/totally_lazy/pair.rb', line 44

def to_s
  "(#{first}, #{second})"
end