Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RPNCalculator
- def initialize
- @calculator = []
- end
- def push(num)
- @calculator << num
- end
- def plus
- @calculator << @calculator.pop + @calculator.pop
- end
- def times
- @calculator << @calculator.pop * @calculator.pop
- end
- def minus
- @calculator << -1 * @calculator.pop + @calculator.pop
- end
- def divide
- @calculator << (1 / @calculator.pop.to_f) * @calculator.pop
- end
- def value
- @calculator.last
- end
- end
Add Comment
Please, Sign In to add comment