Class: RPN::Calculator
- Inherits:
-
Object
- Object
- RPN::Calculator
- Defined in:
- lib/rpn/calculator.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Calculator
constructor
A new instance of Calculator.
- #solve(string) ⇒ Object
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 = {} arity, delimiter = [:arity] || 2, [:delimiter] || ' ' @stack = Stack.new(arity) @parser = Parser.new(delimiter) end |
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
3 4 5 |
# File 'lib/rpn/calculator.rb', line 3 def parser @parser end |
#stack ⇒ Object (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 |