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

Included in:
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

Returns:

  • (Boolean)


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

def even?
  self % 2 == 0
end

#odd?Boolean

Returns:

  • (Boolean)


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

def odd?
  !even?
end