Module: SimpleCalcu

Defined in:
lib/simple_calcu.rb,
lib/simple_calcu/version.rb

Overview

All code in the gem is namespaced under this module.

Constant Summary collapse

VERSION =

The current version of SimpleCalcu

"0.0.3"

Class Method Summary collapse

Class Method Details

.add(number1, number2) ⇒ Object

Adds given two numbers


7
8
9
# File 'lib/simple_calcu.rb', line 7

def self.add(number1, number2)
  number1 + number2
end

.calculate(number1, operator, number2) ⇒ Object

Main calculator method. Requires 3 arguments First and Last arguments must be numbers Second argument could be “+”, “-”, “*” or “/” and must be string


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/simple_calcu.rb', line 29

def self.calculate(number1, operator, number2)
  case operator
  when "+"
    add(number1, number2)
  when "-"
    sub(number1, number2)
  when "*"
    mul(number1, number2)
  when "/"
    div(number1, number2)
  end
end

.div(number1, number2) ⇒ Object

Divides given number2 to number1


22
23
24
# File 'lib/simple_calcu.rb', line 22

def self.div(number1, number2)
  number1 / number2
end

.mul(number1, number2) ⇒ Object

Multiplies given two numbers


17
18
19
# File 'lib/simple_calcu.rb', line 17

def self.mul(number1, number2)
  number1 * number2
end

.sub(number1, number2) ⇒ Object

Subtracts given number1 from number2


12
13
14
# File 'lib/simple_calcu.rb', line 12

def self.sub(number1, number2)
  number1 - number2
end