Solution: Design a Basic Calculator
Go over the implementation of a simple calculator as a class.
We'll cover the following...
Solution
Press + to interact
class Calculatordef add(a, b)return a + benddef minus(a, b)return a - bendend# A sample test casecalc = Calculator.newputs calc.add(2, 3)puts calc.minus(17, calc.add(2, 3))
Explanation
Lines 1–9: We define the
Calculator
class with two methods—add
, defined on ...