Getting Started with Classes

Learn about writing classes.

We'll cover the following

Writing classes

We’re now finally ready for our own classes. Because nearly everything’s an object in Ruby, we’ve worked with objects quite a bit.

We’ve created numbers and strings, and we’ve seen objects like true, false, and nil. We’ve also looked at their class names by calling, "a string".class, and we’ve explored some other methods that these objects have. We’ve also learned how we can define our own methods and how we can call them, passing arguments as required.

That means we now have all the tools that we need to finally learn how to define and use our own classes. This is where things become even more fun!

We’ll define this exact class in just a few lessons. However, before we do that, we’ll first look at how to define the add_two method to a Calculator class.