Class: Prime8::Generators::EratosthenesGenerator

Inherits:
PrimeGenerator show all
Defined in:
lib/prime_8/generators/eratosthenes_generator.rb

Instance Method Summary collapse

Methods inherited from PrimeGenerator

#each, #upper_bound, #upper_bound=, #with_object

Constructor Details

#initializeEratosthenesGenerator

Returns a new instance of EratosthenesGenerator.



6
7
8
9
10
# File 'lib/prime_8/generators/eratosthenes_generator.rb', line 6

def initialize
  @last_prime_index = -1
  @strategy = Prime8::Strategies.eraatosthenes
  super
end

Instance Method Details

#rewindObject



17
18
19
# File 'lib/prime_8/generators/eratosthenes_generator.rb', line 17

def rewind
  initialize
end

#succObject Also known as: next



12
13
14
15
# File 'lib/prime_8/generators/eratosthenes_generator.rb', line 12

def succ
  @last_prime_index += 1
  @strategy.get_nth_prime(@last_prime_index)
end