7 CREATING CLASSES

Classes are the foundation of object-oriented programming (OOP). A class is a blueprint; an object is an instance of a class. Since everything in Ruby is an object, even a basic Hello, World! example makes use of OOP. Although Ruby provides tons of functionality through its built-in classes, you’ll eventually want or need to start creating your own.

This chapter introduces the basics of defining and using classes in Ruby. Herein you’ll learn about the syntax, about class variables, and how to write several different types of methods that classes commonly use. You’ll also be introduced to two concepts that separate Ruby from many other OOP languages. The first is the ease with which you can redefine existing Ruby classes. ...

Get Ruby: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.