Class: Prime::EratosthenesGenerator

Inherits:
PseudoPrimeGenerator show all
Defined in:
lib/backports/1.9.1/stdlib/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

Methods included from Enumerable

#all_with_pattern?, #any_with_pattern?, #chain, #chunk, #chunk_while, #count, #cycle, #drop, #drop_while, #each_entry, #each_with_index_with_optional_args_and_block, #each_with_object, #entries_with_optional_arguments, #filter_map, #find_index, #first, #flat_map, #grep_v, #group_by, #inject_with_symbol, #lazy, #max_by, #min_by, #minmax, #minmax_by, #none?, #none_with_pattern?, #one?, #one_with_pattern?, #reverse_each, #slice_after, #slice_before, #slice_when, #sum, #take, #take_while, #tally, #to_a_with_optional_arguments, #to_h, #to_h_with_block, #uniq

Constructor Details

#initializeEratosthenesGenerator

Returns a new instance of EratosthenesGenerator.


309
310
311
312
# File 'lib/backports/1.9.1/stdlib/prime.rb', line 309

def initialize
  @last_prime_index = -1
  super
end

Instance Method Details

#rewindObject


318
319
320
# File 'lib/backports/1.9.1/stdlib/prime.rb', line 318

def rewind
  initialize
end

#succObject Also known as: next


314
315
316
317
# File 'lib/backports/1.9.1/stdlib/prime.rb', line 314

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