Class: Prime::Generator23 (Ruby 2.2.4)
Description: Class : Prime::Generator23 - Ruby 2.2.4

- Home
- Core 2.2.4
- Std-lib 2.2.4
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

### Home Classes Methods

### In Files

- prime.rb

### Parent

Prime::PseudoPrimeGenerator

### Methods

- ::new
- #next
- #rewind
- #succ

### Class/Module Index

Quicksearch

- Integer
- Prime
- Prime::EratosthenesGenerator
- Prime::EratosthenesSieve
- Prime::Generator23
- Prime::OldCompatibility
- Prime::PseudoPrimeGenerator
- Prime::TrialDivision
- Prime::TrialDivisionGenerator

No matching classes.

# Prime::Generator23

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.

### Public Class Methods

new() click to toggle source

                   # File prime.rb, line 346
    def initialize
      @prime = 1
      @step = nil
      super
    end

### Public Instance Methods

next() click to toggle source
Alias for: succ
rewind() click to toggle source

                   # File prime.rb, line 366
    def rewind
      initialize
    end

succ() click to toggle source

                   # File prime.rb, line 352
    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
      return @prime
    end

Also aliased as: next