Class: CompositeSequence

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prime) ⇒ CompositeSequence

Returns a new instance of CompositeSequence.



7
8
9
10
# File 'lib/composite_sequence.rb', line 7

def initialize(prime)
  @base = prime
  @current = 2 * prime
end

Class Method Details

.of_base_prime(prime) ⇒ Object



3
4
5
# File 'lib/composite_sequence.rb', line 3

def self.of_base_prime(prime)
  self.new(prime)
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
# File 'lib/composite_sequence.rb', line 16

def <=>(other)
  self.next <=> other.next
end

#nextObject



12
13
14
# File 'lib/composite_sequence.rb', line 12

def next
  @current
end

#take_next!Object



20
21
22
23
24
# File 'lib/composite_sequence.rb', line 20

def take_next!
  self.next.tap do
    @current += @base
  end
end