Class: RPN::Calculator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Calculator

Returns a new instance of Calculator.



4
5
6
7
8
9
# File 'lib/rpn/calculator.rb', line 4

def initialize options = {}
  arity, delimiter = options[:arity] || 2,
                     options[:delimiter] || ' '
  @stack = Stack.new(arity)
  @parser = Parser.new(delimiter)
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



3
4
5
# File 'lib/rpn/calculator.rb', line 3

def parser
  @parser
end

#stackObject (readonly)

Returns the value of attribute stack.



3
4
5
# File 'lib/rpn/calculator.rb', line 3

def stack
  @stack
end

Instance Method Details

#solve(string) ⇒ Object



10
11
12
# File 'lib/rpn/calculator.rb', line 10

def solve string
  stack.solve parser.parse(string)
end