Class: Prime::EratosthenesGenerator

Inherits:
PseudoPrimeGenerator show all
Defined in:
lib/prime.rb

Overview

An implementation of PseudoPrimeGenerator.

Uses EratosthenesSieve.

Instance Method Summary collapse

Methods inherited from PseudoPrimeGenerator

#each, #size, #upper_bound, #upper_bound=, #with_index, #with_object

Constructor Details

#initializeEratosthenesGenerator

Returns a new instance of EratosthenesGenerator.



313
314
315
316
# File 'lib/prime.rb', line 313

def initialize
  @last_prime_index = -1
  super
end

Instance Method Details

#rewindObject



322
323
324
# File 'lib/prime.rb', line 322

def rewind
  initialize
end

#succObject Also known as: next



318
319
320
321
# File 'lib/prime.rb', line 318

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