Class: Integer

### Home Classes Methods

### In Files

- lib/backports/1.8.7/integer/even.rb
- lib/backports/1.8.7/integer/odd.rb
- lib/backports/1.8.7/integer/ord.rb
- lib/backports/1.8.7/integer/pred.rb
- lib/backports/1.9.1/integer/round.rb
- lib/backports/1.9.1/stdlib/prime.rb

### Parent

Object

### Methods

- ::each_prime
- ::from_prime_division
- #even?
- #odd?
- #ord
- #pred
- #prime?
- #prime_division
- #round_with_digits

### 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::StdLib
- Backports::StdLib::LoadedFeatures
- Enumerator
- Enumerator::GeneratorBP
- Enumerator::Lazy
- Enumerator::Yielder
- Matrix
- Matrix::EigenvalueDecomposition
- Matrix::LUPDecomposition
- Random
- Random::Implementation
- Random::MT19937
- Enumerable
- Enumerable::Enumerator
- File
- File::Constants
- ARGF
- Array
- BasicObject
- Binding
- Complex
- Dir
- ENV
- Fixnum
- Float
- GC
- Hash
- IO
- Integer
- Kernel
- Math
- Method
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- OpenStruct
- Proc
- Process
- Range
- Regexp
- Set
- StopIteration
- String
- Struct
- Symbol
- UnboundMethod

No matching classes.

# Integer

### Public Class Methods

each_prime(ubound) click to toggle source

Iterates the given block over all prime numbers.

See `Prime`each for more details.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 40
    def Integer.each_prime(ubound, &block) # :yields: prime
      Prime.each(ubound, &block)
    end

from_prime_division(pd) click to toggle source

Re-composes a prime factorization and returns the product.

See Prime#int_from_prime_division for more details.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 21
    def Integer.from_prime_division(pd)
      Prime.int_from_prime_division(pd)
    end

### Public Instance Methods

even?() click to toggle source

    # File lib/backports/1.8.7/integer/even.rb, line 3
    def even?
      self[0].zero?
    end

odd?() click to toggle source

    # File lib/backports/1.8.7/integer/odd.rb, line 3
    def odd?
      !self[0].zero?
    end

ord() click to toggle source

    # File lib/backports/1.8.7/integer/ord.rb, line 3
    def ord
      self
    end

pred() click to toggle source

    # File lib/backports/1.8.7/integer/pred.rb, line 3
    def pred
      self - 1
    end

prime?() click to toggle source

Returns true if `self` is a prime number, false for a composite.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 33
    def prime?
      Prime.prime?(self)
    end

prime_division(generator = Prime::Generator23.new) click to toggle source

Returns the factorization of `self`.

See Prime#prime_division for more details.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 28
    def prime_division(generator = Prime::Generator23.new)
      Prime.prime_division(self, generator)
    end

round_with_digits(ndigits=0) click to toggle source

    # File lib/backports/1.9.1/integer/round.rb, line 5
    def round_with_digits(ndigits=0)
      ndigits = Backports::coerce_to_int(ndigits)
      case
      when ndigits.zero?
        self
      when ndigits > 0
        raise RangeError if ndigits >= 1<<31
        Float(self)
      else
        pow = 10 ** (-ndigits)
        return 0 if pow.is_a?(Float) # when ndigits hugely negative
        remain = self % pow
        comp = self < 0 ? :<= : :<
        remain -= pow unless remain.send(comp, pow / 2)
        self - remain
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.