Search⌘ K
AI Features

Design a Basic Calculator

Explore how to design a basic calculator in Ruby by defining a Calculator class with add and subtract methods. Understand class creation, method definition, object instantiation, and method invocation in Ruby's object-oriented programming.

Problem

Write a class named Calculator that contains two methods:

  • add: To add two numbers
  • minus: To subtract two numbers

Expected output

We'll test the class by creating an object of the class, and invoking its methods on the object to verify that they return the ...