Class: PrimeLib::GeneratorProduct

Inherits:
Generator
  • Object
show all
Includes:
Decorator::TableProduct
Defined in:
lib/prime_lib/generator_product.rb

Instance Method Summary collapse

Methods included from Decorator::TableProduct

#lister, #lister_keys, #to_table

Methods inherited from Generator

#method_added

Methods included from Decorator::Table

#lister, #lister_keys, #to_table

Constructor Details

#initialize(*args) ⇒ GeneratorProduct

Returns a new instance of GeneratorProduct.



6
7
8
9
# File 'lib/prime_lib/generator_product.rb', line 6

def initialize(*args)
  super(*args)
  @product = 1
end

Instance Method Details

#each_with_indexObject



11
12
13
14
15
16
# File 'lib/prime_lib/generator_product.rb', line 11

def each_with_index
  retrieve_primes.each_with_index do |prime, iprime|
    @product *= prime
    yield(iprime, prime, @product)
  end
end

#to_aObject



18
19
20
21
22
23
24
# File 'lib/prime_lib/generator_product.rb', line 18

def to_a
  ret_primes = []
  each_with_index do |iprime, prime, product|
    ret_primes << [iprime, prime, product]
  end
  ret_primes
end