Ruby Meta programming

Source: Internet
Author: User

An object model

Kernel Module

Kernel.private_instance_methods.grep (/^pr/)

Private method

1 If a method recipient is not your own, be sure to specify a recipient

2 Private methods can only specify one implied recipient (private method of the tunable superclass)

The class itself is an object of class. The name of the class is a constant

Class

Include module when M is inserted into the ancestor chain, just above the class

Two methods

Obj.send (: Method,arg) #动态派发 Ojb.method (ARG)

Module#define_method #动态方法 instead of Def

String#grep () {}

def method_missing (Method,*args)

Puts "you Called:#{method} (#{args.join (', ')}"

End

Three blocks

Kernel#local_variables () Tracking the name of the binding

Ruby Scopes do not look outside as nested inside java/c#

class definition, module definition, method call Close the previous scope

Instance_eval

Instance_exec Available Parameters

Packaging code

Proc Lambda

&proc represents a block of code

The return in proc indicates that it is returned from the defined scope

Lambda Ruturn represents the return in the lambda

Ruby Meta programming

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.