123456789_123456789_123456789_123456789_123456789_

Class: Prime::EratosthenesGenerator

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, PseudoPrimeGenerator, Enumerable
Inherits: Prime::PseudoPrimeGenerator
Defined in: lib/prime.rb

Overview

An implementation of PseudoPrimeGenerator.

Uses EratosthenesSieve.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

PseudoPrimeGenerator - Inherited

#each

Iterates the given block for each prime number.

#next

alias of #succ.

#rewind

Rewinds the internal position for enumeration.

#size,
#succ

returns the next pseudo-prime number, and move the internal position forward.

#with_index

see Enumerator#with_index.

#with_object

see Enumerator#with_object.

Constructor Details

.newEratosthenesGenerator

[ GitHub ]

  
# File 'lib/prime.rb', line 310

def initialize
  @last_prime_index = -1
  super
end

Instance Method Details

#next

Alias for #succ.

[ GitHub ]

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

alias next succ

#rewind

[ GitHub ]

  
# File 'lib/prime.rb', line 319

def rewind
  initialize
end

#succ Also known as: #next

[ GitHub ]

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

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