Class: Prime::PseudoPrimeGenerator

### Home Classes Methods

### In Files

- lib/backports/1.9.1/stdlib/prime.rb

### Parent

Object

### Methods

- ::new
- #each
- #next
- #rewind
- #succ
- #upper_bound
- #upper_bound=
- #with_object

### Included Modules

- Enumerable

### Class/Module Index

Quicksearch

- Prime
- Prime::EratosthenesGenerator
- Prime::EratosthenesSieve
- Prime::Generator23
- Prime::OldCompatibility
- Prime::PseudoPrimeGenerator
- Prime::TrialDivision
- Prime::TrialDivisionGenerator
- Backports
- Backports::MOST_EXTREME_OBJECT_EVER
- Backports::Random
- Backports::Random::Implementation
- Backports::Random::MT19937
- Backports::StdLib
- Backports::StdLib::LoadedFeatures
- Enumerator
- Enumerator::GeneratorBP
- Enumerator::Lazy
- Enumerator::Yielder
- Matrix
- Matrix::EigenvalueDecomposition
- Matrix::LUPDecomposition
- Enumerable
- Enumerable::Enumerator
- File
- File::Constants
- ARGF
- Array
- BasicObject
- Bignum
- Binding
- Complex
- Dir
- ENV
- Fixnum
- Float
- GC
- Hash
- IO
- Integer
- Kernel
- Math
- Method
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- OpenStruct
- Proc
- Process
- Random
- Range
- Regexp
- Set
- StopIteration
- String
- Struct
- Symbol
- UnboundMethod

No matching classes.

# Prime::PseudoPrimeGenerator

An abstract class for enumerating pseudo-prime numbers.

Concrete subclasses should override succ, next, rewind.

### Public Class Methods

new(ubound = nil) click to toggle source

    # File lib/backports/1.9.1/stdlib/prime.rb, line 228
    def initialize(ubound = nil)
      @ubound = ubound
    end

### Public Instance Methods

each(&block) click to toggle source

Iterates the given block for each prime numbers.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 260
    def each(&block)
      return self.dup unless block
      if @ubound
        last_value = nil
        loop do
          prime = succ
          break last_value if prime > @ubound
          last_value = block.call(prime)
        end
      else
        loop do
          block.call(succ)
        end
      end
    end

next() click to toggle source

alias of `succ`.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 248
    def next
      raise NotImplementedError, "need to define `next'"
    end

rewind() click to toggle source

Rewinds the internal position for enumeration.

See `Enumerator` rewind.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 255
    def rewind
      raise NotImplementedError, "need to define `rewind'"
    end

succ() click to toggle source

returns the next pseudo-prime number, and move the internal position forward.

`PseudoPrimeGenerator` succ raises `NotImplementedError`.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 243
    def succ
      raise NotImplementedError, "need to define `succ'"
    end

upper_bound() click to toggle source

    # File lib/backports/1.9.1/stdlib/prime.rb, line 235
    def upper_bound
      @ubound
    end

upper_bound=(ubound) click to toggle source

    # File lib/backports/1.9.1/stdlib/prime.rb, line 232
    def upper_bound=(ubound)
      @ubound = ubound
    end

with_object(obj) click to toggle source

see `Enumerator` with_object.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 280
    def with_object(obj)
      return enum_for(:with_object) unless block_given?
      each do |prime|
        yield prime, obj
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.