Created
June 16, 2012 01:05
-
-
Save pzaich/2939443 to your computer and use it in GitHub Desktop.
RPN calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RPNCalculator | |
| def initialize | |
| @calc_array= [] | |
| end | |
| def push(num) | |
| @calc_array << num | |
| end | |
| def plus | |
| @calc_array.reverse.each do |number| | |
| @calc_array.last = number | |
| end | |
| end | |
| def minus | |
| @value = @calc_array[-2] - @calc_array.last | |
| end | |
| def times | |
| @value = @calc_array[-2] * @calc_array[-1] | |
| end | |
| def divide | |
| @value = @calc_array[-2] * @calc_array[-1] | |
| end | |
| def value | |
| @value = @calc_array.last | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment