Ruby Object Model summary

Reference "the Ruby program element" meta-programming, i.e., the code used to write the code.

  • A set of objects referenced by the instance variable and a class consisting of
  • There is a method of an object class and object belongs, like in the prototype js, precisely in the ruby, the method should be examples
  • The class itself is the formation of the Class class, the class name, but it is a constant
  • Module Class class is a subclass of the module package essentially consisting of a set of methods. In addition to having a characteristic class module, it may also be instantiated in a hierarchical
  • Constants like file system, organized in a tree structure
  • Each class has an ancestor chain, the chain starting with the class they belong to, know BasicObject end up class
  • When you call a method, Ruby came to the first class of the recipient, and then look up the ancestor chain until you find a way, or to reach the top of the chain
  • Whenever class contains a module that is inserted into the ancestor chain directly above the current class
  • When you call a method, the receiver is self
  • When defining a module, the module is self
  • Instance variable will always be recognized as self
  • Any method does not explicitly specify the recipient is called, as the main call

Reproduced in: https: //my.oschina.net/u/204616/blog/545232

Guess you like

Origin blog.csdn.net/weixin_34367845/article/details/91990073