Module: ActiveSupport::CoreExtensions::Fixnum::EvenOdd

Included in:
Bignum, Fixnum
Defined in:
lib/active_support/core_ext/fixnum/even_odd.rb

Overview

For checking if a fixnum is even or odd.

  • 1.even? # => false

  • 1.odd? # => true

  • 2.even? # => true

  • 2.odd? # => false

Instance Method Summary collapse

Instance Method Details

#even?Boolean


14
15
16
# File 'lib/active_support/core_ext/fixnum/even_odd.rb', line 14

def even?
  multiple_of? 2
end

#multiple_of?(number) ⇒ Boolean


10
11
12
# File 'lib/active_support/core_ext/fixnum/even_odd.rb', line 10

def multiple_of?(number)
  self % number == 0
end

#odd?Boolean


18
19
20
# File 'lib/active_support/core_ext/fixnum/even_odd.rb', line 18

def odd?
  !even?
end