Object-Oriented Programming is a programming paradigm, in other words, it's a way to think about how you write code.

The main idea in OOP is the concept of objects.

An object can hold data & a set of operations. We call these operations "methods".

To create objects in Ruby you will need a class.

Here's an example:

class Book

A class defines a blueprint for an object.

Just like a blueprint for a car, a phone or a building, if you have the blueprint you can make copies of that.

So in this case we have a simple blueprint for a Book object.

Here's how we can use it to create objects:

book1 = Book.new
book2 = Book.new

Here we have two Book objects. Each of these objects is unique & has it's own indentity (think serial number).


What can we do this these objects?

Not much, since we haven't defined any operations (methods).

But there are some operations that are available on all Ruby objects.

For example, you can ask for the class name of an object:

# Book

Key Concept!

Notice this syntax:


Where object in our example is book1 and the method is class.

This is how you tell Ruby objects to do something.

In the next lesson you will learn how to define your very own methods so you can tell Ruby how this object should behave.