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.



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

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



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

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