Class: Dubcalculator::Basic
- Inherits:
-
Object
- Object
- Dubcalculator::Basic
- Defined in:
- lib/dubcalculator.rb
Overview
This is the basic class for the calculator
Class Method Summary collapse
-
.add(num1, num2) ⇒ Object
This method adds two numbers.
-
.divide(num1, num2) ⇒ Object
This method divides two numbers.
-
.multiply(num1, num2) ⇒ Object
This method multiplies two numbers.
-
.subtract(num1, num2) ⇒ Object
This method subtracts two numbers.
Class Method Details
.add(num1, num2) ⇒ Object
This method adds two numbers
11 12 13 14 15 16 17 |
# File 'lib/dubcalculator.rb', line 11 def self.add(num1, num2) raise 'Invalid argument' if validate_numbers(num1, num2) num1 + num2 rescue StandardError nil end |
.divide(num1, num2) ⇒ Object
This method divides two numbers
38 39 40 41 42 43 44 45 |
# File 'lib/dubcalculator.rb', line 38 def self.divide(num1, num2) raise 'Invalid argument' if validate_numbers(num1, num2) raise 'Cannot divide by zero' if num2.zero? num1 / num2 rescue StandardError nil end |
.multiply(num1, num2) ⇒ Object
This method multiplies two numbers
29 30 31 32 33 34 35 |
# File 'lib/dubcalculator.rb', line 29 def self.multiply(num1, num2) raise 'Invalid argument' if validate_numbers(num1, num2) num1 * num2 rescue StandardError nil end |
.subtract(num1, num2) ⇒ Object
This method subtracts two numbers
20 21 22 23 24 25 26 |
# File 'lib/dubcalculator.rb', line 20 def self.subtract(num1, num2) raise 'Invalid argument' if validate_numbers(num1, num2) num1 - num2 rescue StandardError nil end |