Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/core/numeric.rb

Instance Method Summary collapse

Instance Method Details

#evenize(operator = '+') ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
# File 'lib/core/numeric.rb', line 3

def evenize(operator = '+')
  raise ArgumentError, "invalid argument (must be `+' or `-')" unless %w(+ -).include?(operator)
  round.send(operator, modulo(2))
end

#oddize(operator = '+') ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/core/numeric.rb', line 8

def oddize(operator = '+')
  raise ArgumentError, "invalid argument (must be `+' or `-')" unless %w(+ -).include?(operator)
  self %2 > 0 ? self : round.send(operator, 1)
end