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.
1 2 3 4 5 |
# Student.rb class Student end |
In Java, this is equivalent to
1 2 3 |
public class Student { } |
Creating Objects from a class
Given the above Ruby class code, we’d create an object of that class this way:
1 |
mike = Student.new |
In Java, this is equivalent to
1 |
Student mike = new Student(); |