Class: Prime::Generator23
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
PseudoPrimeGenerator
|
|
Instance Chain:
self,
PseudoPrimeGenerator,
Enumerable
|
|
Inherits: |
Prime::PseudoPrimeGenerator
|
Defined in: | lib/prime.rb |
Overview
Generates all integers which are greater than 2 and are not divisible by either 2 or 3.
This is a pseudo-prime generator, suitable on checking primality of an integer by brute force method.
Class Method Summary
Instance Attribute Summary
PseudoPrimeGenerator - Inherited
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 |
#with_object | see |
Constructor Details
.new ⇒ Generator23
# File 'lib/prime.rb', line 349
def initialize @prime = 1 @step = nil super end
Instance Method Details
#next
Alias for #succ.
# File 'lib/prime.rb', line 368
alias next succ
#rewind
[ GitHub ]# File 'lib/prime.rb', line 369
def rewind initialize end
#succ Also known as: #next
[ GitHub ]# File 'lib/prime.rb', line 355
def succ if (@step) @prime += @step @step = 6 - @step else case @prime when 1; @prime = 2 when 2; @prime = 3 when 3; @prime = 5; @step = 2 end end @prime end