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, #upper_bound, #upper_bound=, #with_object

Constructor Details

#initializeEratosthenesGenerator

Returns a new instance of EratosthenesGenerator.



308
309
310
311
# File 'lib/prime.rb', line 308

def initialize
  @last_prime = nil
  super
end

Instance Method Details

#rewindObject



316
317
318
# File 'lib/prime.rb', line 316

def rewind
  initialize
end

#succObject Also known as: next



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

def succ
  @last_prime = @last_prime ? EratosthenesSieve.instance.next_to(@last_prime) : 2
end