Class: PrimeLib::Generator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Decorator::Table
Defined in:
lib/prime_lib/generator.rb,
lib/prime_lib/generator/gen_engine.rb,
lib/prime_lib/generator/sieve_of_eratosthenes.rb,
lib/prime_lib/generator/sieve_of_eratosthenes_c.rb

Direct Known Subclasses

GeneratorProduct

Defined Under Namespace

Classes: GenEngine, SieveOfEratosthenes, SieveOfEratosthenesC

Instance Method Summary collapse

Methods included from Decorator::Table

#lister, #lister_keys, #to_table

Constructor Details

#initialize(max_els = 100, engine: SieveOfEratosthenes.new) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
# File 'lib/prime_lib/generator.rb', line 10

def initialize(max_els = 100, engine: SieveOfEratosthenes.new)
  @engine = engine
  engine.max_els = max_els
  @max_els = max_els
end

Instance Method Details

#each_with_indexObject



20
21
22
23
24
# File 'lib/prime_lib/generator.rb', line 20

def each_with_index
  retrieve_primes.each_with_index do |prime, iprime|
    yield(prime, iprime)
  end
end

#method_added(method) ⇒ Object



16
17
18
# File 'lib/prime_lib/generator.rb', line 16

def method_added(method)
  (class<< self;self;end).def_delegator :instance, method
end

#to_aObject



26
27
28
# File 'lib/prime_lib/generator.rb', line 26

def to_a
  retrieve_primes
end