Class: Calculator
- Inherits:
-
Object
- Object
- Calculator
- Defined in:
- lib/it_tools/calc.rb
Instance Method Summary collapse
- #add ⇒ Object
- #enter(value) ⇒ Object
-
#initialize ⇒ Calculator
constructor
A new instance of Calculator.
- #screen ⇒ Object
Constructor Details
#initialize ⇒ Calculator
Returns a new instance of Calculator.
2 3 4 |
# File 'lib/it_tools/calc.rb', line 2 def initialize @stack = [] end |
Instance Method Details
#add ⇒ Object
11 12 13 |
# File 'lib/it_tools/calc.rb', line 11 def add @stack.push( @stack.pop + @stack.pop ) end |
#enter(value) ⇒ Object
5 6 7 |
# File 'lib/it_tools/calc.rb', line 5 def enter( value ) @stack.push value end |
#screen ⇒ Object
8 9 10 |
# File 'lib/it_tools/calc.rb', line 8 def screen @stack[0] end |