ruby metaprogramming 03
来源:互联网 发布:霍建华林心如形婚 知乎 编辑:程序博客网 时间:2024/06/06 06:52
Refer to Metaprogramming in Ruby
eval
String can execute as code by eval which is a method of module Kernel.
instance_eval module_eval and class_eval
They are special type of evals.
Objects can use instance_eval to create methods. For classes, methods are class methods. Remember that anonymous class will be created.
module_eval and class_eval operates on classes and modules. By another word, they can not call on pure objects.
class_variables_get and class_variables_get
We can get and set class variables out of class.
class_variables
Method class_variables gives us a list of class variables.
instance_variable_get and instance_variable_set
They give us the ability to get and set the instance variable of object out of class.
const_get and const_set
They give us the ability to get and set the const out of class. Using them, we can even create classes in run time.
Object.const_set("Ruby", Class.new)class_name = Object.const_get("Ruby")class_name.class_eval do def hello puts "hello world" endendr = class_name.newr.hello
- ruby metaprogramming 03
- ruby metaprogramming examples
- ruby metaprogramming 0
- ruby metaprogramming 01
- Ruby元编程技术(Ruby Metaprogramming techniques)
- Ruby元编程技术(Ruby Metaprogramming techniques)
- Metaprogramming in Ruby: It’s All About the Self
- Template Metaprogramming
- Metaprogramming(1)
- template metaprogramming
- MetaProgramming Chapter4
- MetaProgramming Chapter5
- MetaProgramming Chapter6
- the boost c++ metaprogramming
- MetaProgramming 求π源代码
- 关于元编程(Metaprogramming)
- Functional Programming & Template Metaprogramming
- Metaprogramming in Python
- 最坏情况为线性时间的选择算法
- leetcode:leetcode :Path Sum
- windows系统下CMAKE编译QJSON
- logmnr 的使用
- HTML5 Canvas知识点学习笔记
- ruby metaprogramming 03
- Java中ArrayList类的用法
- HDU 2617 Happy 2009(字符串)
- 用VC进行COM编程所必须掌握的理论知识
- OD OC 门
- RadioButton 相应
- 基于Linux平台下的僵尸网络病毒《比尔盖茨》
- PHP 工作原理
- POJ 1088 - 滑雪(动态规划)