...

/

Defining Instance Methods

Defining Instance Methods

This lesson focuses on defining instance methods in Ruby.

If you have read closely methods can be defined and called on objects (i.e. instances), e.g. 1.odd?. And you have just seen that they can also be defined on classes, e.g. Calculator.new.

Fairly straightforward, methods that are available on classes are called class methods, and methods that are available on instances are called instance methods.

In this chapter, we want to add the “stand-alone” methods that we’ve learned to port (move) in the previous chapters Writing Methods to our class Calculator so that they’ll end up as instance methods. ...

Create a free account to access the full course.

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