[Note] "Metaprogramming Ruby"

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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,916评论 0 23
  • Android官网最近推出了一个新的app程序框架,虽然目前正处于alpha阶段,还未正式发布,但其中的实现原理和...
    神秘角度阅读 3,459评论 0 14
  • 随着中国改革开放以来的发展,城市化过程还在不断进行,世界史上最大的人口迁徙—中国农村人进城购房仍在继续,这个时代每...
    雾欣雨鲜阅读 418评论 2 4
  • 我和猫叔的链接 关注“剽悍一只猫”公众号已有半年,猫叔每次推送的文章简短易懂,一直觉得这只猫非常有趣。7月因为猫叔...
    zorafong阅读 334评论 3 7
  • 旧的不去,新的不来-替换定律 故事:有位秀才进京赶考,住在京城一家客栈。考试的前几天,他每天晚上都做梦,最近三天里...
    wangrad阅读 411评论 0 1