美文网首页
[Note] "Metaprogramming Rub

[Note] "Metaprogramming Rub

作者: 王谙然 | 来源:发表于2015-06-07 22:32 被阅读43次

    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

    1. Above all, everthing we can see are objects, except for the reserved word, you can try this 1.object_id or Array.object_id.

    2. Before we dive into the objec model, What's a class's role ?

    3. Define some variables for its instances.

    4. Define a list methods for its instances.

    5. Hold a inheritance chain.

    6. Has new method so that it can make object which can access the class's and his super class's methods.

    7. And then, what's a instance's role?

    8. A instance holding several instance variables to present different states.

    9. 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

    1. BasicObjec: the root of the objec model in ruby.

    2. Object

    3. A class of everything in ruby including build-in Class, Module, custom class instance and so on.

    4. It defines the basic behaviours or attributes of a object such as object_id.

    5. Module

    6. Defined most befaviours a Utility have.

    7. As a super class for Class.

    8. Class

    9. A class of every object who should be instantiated including the Class it self.

    10. It defines what a class object can do such as new, superclass.

    相关文章

      网友评论

          本文标题:[Note] "Metaprogramming Rub

          本文链接:https://www.haomeiwen.com/subject/tttjqttx.html