1.Understand Object Model In Ruby
The object model in ruby is not easy to understand at first, but if you think roles of Class
and Object
over and over again, someday you will grasp the grace of the design for the ruby object model.
Ok, let me show you my understanding:
Basic Object-oriented concepts
Above all, everthing we can see are objects, except for the reserved word, you can try this
1.object_id
orArray.object_id
.Before we dive into the objec model, What's a class's role ?
Define some variables for its instances.
Define a list methods for its instances.
Hold a inheritance chain.
Has new method so that it can make object which can access the class's and his super class's methods.
And then, what's a instance's role?
A instance holding several instance variables to present different states.
Which is the worker for our instructions in the real world, while the class is charge of the definition of a instance's behaviors.
Build-in class in ruby
BasicObjec
: the root of the objec model in ruby.Object
A class of everything in ruby including build-in Class, Module, custom class instance and so on.
It defines the basic behaviours or attributes of a object such as
object_id
.Module
Defined most befaviours a Utility have.
As a super class for
Class
.Class
A class of every object who should be instantiated including the
Class
it self.It defines what a class object can do such as
new
,superclass
.