| 1 | class Calculator |
| 2 | attr_accessor :result |
| 3 | |
| 4 | def initialize |
| 5 | @result = 0 |
| 6 | end |
| 7 | |
| 8 | def add(number) |
| 9 | @result += number |
| 10 | self |
| 11 | end |
| 12 | |
| 13 | def subtract(number) |
| 14 | @result -= number |
| 15 | self |
| 16 | end |
| 17 | |
| 18 | def get_result |
| 19 | @result |
| 20 | end |
| 21 | |
| 22 | def reset |
| 23 | @result = 0 |
| 24 | self |
| 25 | end |
| 26 | end |
| 27 | |
| 28 | calc = Calculator.new |
| 29 | calc.add(5).subtract(3) |
| 30 | puts "Result: #{calc.get_result}" |