Class: Pair
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #enumerator ⇒ Object
- #first ⇒ Object
-
#initialize(first, second) ⇒ Pair
constructor
A new instance of Pair.
- #second ⇒ Object
- #to_s ⇒ Object
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 |
#enumerator ⇒ Object
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 |
#first ⇒ Object
24 25 26 |
# File 'lib/totally_lazy/pair.rb', line 24 def first @first.() end |
#second ⇒ Object
28 29 30 |
# File 'lib/totally_lazy/pair.rb', line 28 def second @second.() end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/totally_lazy/pair.rb', line 44 def to_s "(#{first}, #{second})" end |