class Prime::PseudoPrimeGenerator

Concrete subclasses should override succ, next, rewind.
An abstract class for enumerating pseudo-prime numbers.

def each

Iterates the given block for each prime number.
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

def initialize(ubound = nil)

def initialize(ubound = nil)
  @ubound = ubound
end

def next

alias of +succ+.
def next
  raise NotImplementedError, "need to define `next'"
end

def rewind

See +Enumerator+#rewind.

Rewinds the internal position for enumeration.
def rewind
  raise NotImplementedError, "need to define `rewind'"
end

def size

def size
  Float::INFINITY
end

def succ

+PseudoPrimeGenerator+#succ raises +NotImplementedError+.

position forward.
returns the next pseudo-prime number, and move the internal
def succ
  raise NotImplementedError, "need to define `succ'"
end

def upper_bound

def upper_bound
  @ubound
end

def upper_bound=(ubound)

def upper_bound=(ubound)
  @ubound = ubound
end

def with_index(offset = 0)

see +Enumerator+#with_index.
def with_index(offset = 0)
  return enum_for(:with_index, offset) { Float::INFINITY } unless block_given?
  return each_with_index(&proc) if offset == 0
  each do |prime|
    yield prime, offset
    offset += 1
  end
end

def with_object(obj)

see +Enumerator+#with_object.
def with_object(obj)
  return enum_for(:with_object, obj) { Float::INFINITY } unless block_given?
  each do |prime|
    yield prime, obj
  end
end