Guest User

Untitled

a guest
Oct 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class RPNCalculator
  2. def initialize
  3. @calculator = []
  4. end
  5.  
  6. def push(num)
  7. @calculator << num
  8. end
  9.  
  10. def plus
  11. @calculator << @calculator.pop + @calculator.pop
  12. end
  13. def times
  14. @calculator << @calculator.pop * @calculator.pop
  15. end
  16. def minus
  17. @calculator << -1 * @calculator.pop + @calculator.pop
  18. end
  19. def divide
  20. @calculator << (1 / @calculator.pop.to_f) * @calculator.pop
  21. end
  22. def value
  23. @calculator.last
  24. end
  25.  
  26. end
Add Comment
Please, Sign In to add comment