Ruby : Classes, Object, Inheritance, Module , Mixin
Class name starts with a capitabl letter.And class definition itself is a object of the Class class.Instance Variable for a class starts with @.And class variable starts with @@. to set it you can user attr,attr_reader,attr_writer,attr_accessor followed by :field-name.
Class method start with class name .whereas the object/instance methods are defined with a small letter.
There are 2 type of objects
1. Normal Object which has the instance variables and variable to indicate/pointer to thier class/ list .A class is what charactersitics/methods and what is thier ancestory if they don’t have the characteristic /method in them.
2.Class Object are objects which have instance variables and variable to indicate/pointer to thier class/list.Also they have a table to hold its methods .Any object of this class type will have these methods.It also has a super which point to the ancestory the class has.As for as the class methods…/class object methods it gets from it klass pointer and the methods contained in that..
MetaClass/Singleton classes are classes to change the behaviour for one particular object.Since class Object is of type class and if it need a class method…or an extra method for this object alone class A end…then it would create a thier singleton object and store the methods in it.So when ever there is a invocation of methods the first place that is looked is the metaclass/singleton class before moving on to the klass .you can open a meta class by using the syntax class <<self; def meth; end; end;.Also you can the class itself for a brief moment by using class <<self;self;end;self within the opening is the meta class itself.
The self within class A end is the Object A.and self in a method is the objA of type/class A and self within class <<self ; self; end; is the singleton class.
define_method is a private method in module .In ruby it is possible to call private method from the object of a class Class where the definition is,provided it doesn’t have reciever…(it is not method call on an object)…