In Files
- prime.rb
Parent
Object
Included Modules
- Enumerable
Prime::PseudoPrimeGenerator
An abstract class for enumerating pseudo-prime numbers.
Concrete subclasses should override succ, next, rewind.
Public Class Methods
Public Instance Methods
each()
Iterates the given block for each prime number.
# File prime.rb, line 265
def each
return self.dup unless block_given?
if @ubound
last_value = nil
loop do
prime = succ
break last_value if prime > @ubound
last_value = yield prime
end
else
loop do
yield succ
end
end
end
next()
alias of succ.
# File prime.rb, line 253
def next
raise NotImplementedError, "need to define `next'"
end
rewind()
Rewinds the internal position for enumeration.
See Enumerator#rewind.
# File prime.rb, line 260
def rewind
raise NotImplementedError, "need to define `rewind'"
end
succ()
returns the next pseudo-prime number, and move the internal position forward.
PseudoPrimeGenerator#succ raises
NotImplementedError.
# File prime.rb, line 248
def succ
raise NotImplementedError, "need to define `succ'"
end