Class vs Object
Class is the blueprint from which individual objects are created. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles.
Variables in a Ruby Class
Instance Variables: Instance variables are available across methods for any particular instance or object. That means that instance variables change from object to object. Instance variables are preceded by the at sign (@) followed by the variable name.
Class Variables: Class variables are available across different objects. A class variable belongs to the class and is a characteristic of a class. They are preceded by the sign @@ and are followed by the variable name. We don't really use class variable much..
Ruby Pseudo-Variables
They are special variables that have the appearance of local variables but behave like constants. You can not assign any value to these variables.
Module
Modules are a way of grouping together methods, classes, and constants. Modules give you two major benefits.
Modules define a namespace, a sandbox in which your methods and constants can play without having to worry about being stepped on by other methods and constants.
Mixins in Ruby
Ruby does not support multiple inheritance directly but Ruby Modules have another wonderful use called a mixin.
Self
Class methods do not have access to instance methods or instance variables. However instance methods can access both class methods and class variables.
Self can also help to organize classes by separating responsibilities. Here is the example.
In order to convert order to pdf @order.converter.to_pdf In object-oriented circles, this is known as composition.