Class: Multipri::PrimesTable
- Inherits:
-
Object
- Object
- Multipri::PrimesTable
- Defined in:
- lib/multipri/primes_table.rb
Defined Under Namespace
Classes: Row
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(size) ⇒ PrimesTable
constructor
A new instance of PrimesTable.
- #row_titles ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(size) ⇒ PrimesTable
Returns a new instance of PrimesTable.
29 30 31 32 |
# File 'lib/multipri/primes_table.rb', line 29 def initialize(size) @size = size @generated = false end |
Class Method Details
.generate(size) ⇒ Object
25 26 27 |
# File 'lib/multipri/primes_table.rb', line 25 def self.generate(size) new(size).generate end |
Instance Method Details
#generate ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/multipri/primes_table.rb', line 34 def generate primes = Prime.new.first(@size) @row_titles = primes @rows = primes.map do |p| Row.new(p, primes.map { |q| p * q }) end @generated = true self end |
#row_titles ⇒ Object
49 50 51 52 |
# File 'lib/multipri/primes_table.rb', line 49 def row_titles generate unless generated? @row_titles end |
#rows ⇒ Object
44 45 46 47 |
# File 'lib/multipri/primes_table.rb', line 44 def rows generate unless generated? @rows end |