Module: ReversePolishCalculator::Errors

Defined in:
lib/reverse-polish-calculator/errors.rb

Constant Summary collapse

MethodMapping =
{
  NoMethodError => :no_method_error,
  Math::DomainError => :math_domain_error
}
Classes =
MethodMapping.keys

Class Method Summary collapse

Class Method Details

.handle(exception) ⇒ Object



11
12
13
# File 'lib/reverse-polish-calculator/errors.rb', line 11

def self.handle(exception)
  send(MethodMapping[exception.class], exception)
end

.math_domain_error(exception) ⇒ Object



20
21
22
23
24
# File 'lib/reverse-polish-calculator/errors.rb', line 20

def self.math_domain_error(exception)
  name = exception.message.match(/"(.+)"/)[1]
  ReversePolishCalculator.stack.remove(name)
  Helpers.multi_puts "Bad value for '#{name}'"
end

.no_method_error(exception) ⇒ Object



15
16
17
18
# File 'lib/reverse-polish-calculator/errors.rb', line 15

def self.no_method_error(exception)
  ReversePolishCalculator.stack.remove(exception.name)
  Helpers.multi_puts "Cannot calculate '#{exception.name}'"
end