Class: Calculator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCalculator

Returns a new instance of Calculator.



8
9
10
# File 'lib/calculator.rb', line 8

def initialize()
  @memory = 0
end

Instance Attribute Details

#memoryObject

Returns the value of attribute memory.



5
6
7
# File 'lib/calculator.rb', line 5

def memory
  @memory
end

Instance Method Details

#eval(expr) ⇒ Object



12
13
14
15
16
# File 'lib/calculator.rb', line 12

def eval(expr)
  parser = Parser.new(StringIO.new(expr))
  ast = parser.parse()
  return ast.evaluate()
end