Class: Prime::EratosthenesGenerator
- Inherits:
-
PseudoPrimeGenerator
- Object
- PseudoPrimeGenerator
- Prime::EratosthenesGenerator
- Defined in:
- lib/prime.rb
Overview
An implementation of PseudoPrimeGenerator
.
Uses EratosthenesSieve
.
Instance Method Summary collapse
-
#initialize ⇒ EratosthenesGenerator
constructor
A new instance of EratosthenesGenerator.
- #rewind ⇒ Object
- #succ ⇒ Object (also: #next)
Methods inherited from PseudoPrimeGenerator
#each, #size, #upper_bound, #upper_bound=, #with_index, #with_object
Constructor Details
#initialize ⇒ EratosthenesGenerator
Returns a new instance of EratosthenesGenerator.
411 412 413 414 |
# File 'lib/prime.rb', line 411 def initialize @last_prime_index = -1 super end |
Instance Method Details
#rewind ⇒ Object
420 421 422 |
# File 'lib/prime.rb', line 420 def rewind initialize end |
#succ ⇒ Object Also known as: next
416 417 418 419 |
# File 'lib/prime.rb', line 416 def succ @last_prime_index += 1 EratosthenesSieve.instance.get_nth_prime(@last_prime_index) end |