Module: CalcRubyTestGem

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

Defined Under Namespace

Classes: Error, UnsupportedOperation

Constant Summary collapse

ALLOWED_OPERATIONS =
['+', '-', '/', '*'].freeze
VERSION =
"0.2.2"

Class Method Summary collapse

Class Method Details

.calculate(first_operand, second_operand, operation) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
# File 'lib/calc_ruby_test_gem.rb', line 13

def self.calculate(first_operand, second_operand, operation)
  raise ArgumentError if first_operand.class == String || second_operand.class == String
  raise UnsupportedOperation unless ALLOWED_OPERATIONS.include? operation
  
  begin
  "#{first_operand} #{operation} #{second_operand} = #{first_operand.send(operation, second_operand)}"      
  rescue ZeroDivisionError => e
    "Division by zero is not allowed."
  end
end