Ruby – How to create a Class and its Object

This post demonstrates how to create a very simple class and to create objects from that class.

Creating a Class in Ruby

Creating a class in Ruby is straightforward. If you’ve worked with other OOP languages such as Java before then this just a review (of concepts) for you.

In Java, this is equivalent to

Creating Objects from a class

Given the above Ruby class code, we’d create an object of that class this way:

In Java, this is equivalent to