Ruby metaprogramming and ruby Programming
An object model
Kernel Module
Kernel. private_instance_methods.grep (/^ pr /)
Private method
1. If a method receiver is not yourself, you must specify a receiver.
2. A private method can only specify one implicit receiver (a private method that can be called as a superclass)
The Class itself is the object of the Class. The class name is a constant.
Class <Module, the Module and Class names act as Directory roles and are organized in a tree structure
When the include Module is used, M is inserted into the ancestor chain.
Method 2
Obj. send (: method, arg) # dynamically distribute ojb. method (arg)
Module # define_method # Replace def with a dynamic method
String # grep (){}
Def method_missing (method, * args)
Puts "you called: # {method} (# {args. join (',')}"
End
Sanblocks
Kernel # local_variables () trace the bound name
The ruby scope is not similar to the nested inside java/c #.
Class Definition, module definition, closing the previous scope when calling a method
Instance_eval
Instance_exec Parameter
Packaging code
Proc lambda
& Proc represents a code block
In proc, return indicates that the returned value is from the defined scope.
Lambda ruturn indicates that