Class: Fixnum

Inherits:
Object show all
Defined in:
lib/sixarm_ruby_ramp/fixnum.rb

Overview

Fixnum extensions

Instance Method Summary collapse

Instance Method Details

#even?Boolean

Examples:

2.even? => true
3.even? => false

Returns:

  • (Boolean)

    true if the number is even



18
19
20
# File 'lib/sixarm_ruby_ramp/fixnum.rb', line 18

def even?
  return self & 1 == 0
end

#odd?Boolean

Examples:

2.odd? => false
3.odd? => true

Returns:

  • (Boolean)

    true if the number is odd



31
32
33
# File 'lib/sixarm_ruby_ramp/fixnum.rb', line 31

def odd?
  return self & 1 != 0
end