Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 15, 2012 01:53
Show Gist options
  • Save perspectivezoom/2934193 to your computer and use it in GitHub Desktop.
Save perspectivezoom/2934193 to your computer and use it in GitHub Desktop.
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