Created
June 15, 2012 01:53
-
-
Save perspectivezoom/2934193 to your computer and use it in GitHub Desktop.
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() | |
@num_store = [] | |
end | |
def push(n) | |
@num_store << n | |
end | |
def plus | |
@num_store = @num_store[0...-2] << (@num_store[-2] + @num_store[-1]) | |
end | |
def minus | |
@num_store = @num_store[0...-2] << (@num_store[-2] - @num_store[-1]) | |
end | |
def times | |
@num_store = @num_store[0...-2] << (@num_store[-2] * @num_store[-1]) | |
end | |
def divide | |
@num_store = @num_store[0...-2] << (@num_store[-2] / @num_store[-1].to_f) | |
end | |
def value | |
@num_store[-1] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment