Methods
Public Instance methods
even?()

Is an integer even?

  2.even?  #=> true
  3.even?  #=> false
# File lib/facets/core/integer/multiple.rb, line 18
  def even?
    self % 2 == 0
  end
fac()

Alias for factorial

fact()

Alias for factorial

factorial()

Calculate the factorial of an integer.

  2.factorial  #=> 2
  3.factorial  #=> 6
  3.factorial  #=> 24
This method is also aliased as fac fact
# File lib/facets/core/integer/factorial.rb, line 14
  def factorial
    return 1 if zero?
    f = 1
    2.upto(self) { |n| f *= n }
    f
  end
multiple?(number)

Is is a multiple of a given number?

  7.multiple?(2)  #=> false
  8.multiple?(2)  #=> true
# File lib/facets/core/integer/multiple.rb, line 27
  def multiple?(number)
    self % number == 0
  end
odd?()

Is an integer odd?

  2.odd?  #=> false
  3.odd?  #=> true
# File lib/facets/core/integer/multiple.rb, line 9
  def odd?
    self % 2 == 1
  end
ordinal()
# File lib/facets/core/integer/ordinal.rb, line 4
  def ordinal
    if (11..13).include?(self % 100)
      "#{self}th"
    else
      case self % 10
        when 1: "#{self}st"
        when 2: "#{self}nd"
        when 3: "#{self}rd"
        else    "#{self}th"
      end
    end
  end
round_at(*args)

To properly support Float’s rounding methods, Integer must also be augmented.

# File lib/facets/core/float/round_at.rb, line 29
  def round_at(*args)
    self.to_f.round_at(*args)
  end
round_to(*args)

To properly support Float’s rounding methods, Integer must also be augmented.

# File lib/facets/core/float/round_to.rb, line 30
  def round_to(*args)
    self.to_f.round_to(*args)
  end
times_collect(&yld)

Like times but returns a collection of the yield results.

  a = 3.times_collect { |i| "#{i+1}" }
  a => [ "1", "2", "3" ]
This method is also aliased as times_map
# File lib/facets/core/integer/times_collect.rb, line 9
  def times_collect(&yld)
    a = []; self.times{ |i| a << yld.call(i) }
    a
  end
times_map(&yld)

Alias for times_collect