You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

calculator.rb 345 B

2 years ago
123456789101112131415161718192021222324252627
  1. class Calculator
  2. def initialize
  3. @stack = []
  4. end
  5. def push(arg)
  6. @stack.push arg
  7. end
  8. def result
  9. @stack.last
  10. end
  11. def +
  12. number_1 = @stack.pop
  13. number_2 = @stack.pop
  14. @stack.push number_1 + number_2
  15. end
  16. def /
  17. divisor = @stack.pop
  18. dividend = @stack.pop
  19. @stack.push dividend / divisor
  20. end
  21. end

No Description

Contributors (1)