aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/integer/even_odd.rb
blob: 6d005268a36591433d37bae8bd025058bfdc5aa2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Integer
  # Check whether the integer is evenly divisible by the argument.
  def multiple_of?(number)
    self % number == 0
  end

  # Is the integer a multiple of 2?
  def even?
    multiple_of? 2
  end if RUBY_VERSION < '1.9'

  # Is the integer not a multiple of 2?
  def odd?
    !even?
  end if RUBY_VERSION < '1.9'
end