Defining Instance Methods

Learn to define instance methods in Ruby.

Methods can be defined and called on objects, like 1.odd?. They can also be defined in classes, like Calculator.new.

Methods that are available in classes are called class methods, and methods that are available on instances are called instance methods.

In this lesson, we want to add the stand-alone methods that we’ve learned about previously to our Calculator class so that they’ll end up as instance methods.

Here’s how we can do that:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy