Ruby metaprogramming: Object Model

Source: Internet
Author: User

  1. An object consists of a group of instance variables and a class reference.

  2. Object methods exist in the class to which the object belongs (from the class perspective, they are called instance methods ).

  3. The class itself is the object of the class. The class name is just a constant.

  4. A class is a subclass of a module. A module is basically a package composed of a group of methods. In addition to the features of modules, classes can also be instantiated (through the new () method) and organized as hierarchies (through its super-class () method ).

  5. Constants, like file systems, are organized in a tree structure. The module and class names play the role of the Directory, while other common constants play the role of the file.

  6. Each class has an ancestor chain, which starts from its own class and ends up until the end of the basicobject class.

  7. When a method is called, Ruby first goes to the class to which the receiver belongs, and then looks up the ancestor chain until the method is found or reached the top of the chain.

  8. Every time a class contains a module, the module is inserted into the ancestor chain and positioned on the top of the class.

  9. When a method is called, the receiver assumes the role of self.

  10. When a module (or class) is defined, the module assumes the role of self.



Ruby metaprogramming: Object Model

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.