...

/

Defining Classes

Defining Classes

This lesson will teach you how to define your own classes in Ruby!

Let’s start by creating a class Calculator, and adding some methods to it, step by step.

In Ruby, you define a class like this:

Press + to interact
class Calculator
end

That’s all. It’s not a very useful class since it’s completely empty, but it’s a class.

💡

A class is defined using the keyword class, a name, and the keyword end.

...

Create a free account to access the full course.

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