classname = 'Integer'eval classname(eval classname).to_seval classname + '.methods'
classname = 'Integer'object = Kernel.const_get(classname)object.methods
#Object.send(methodname)#Object.send(methodname, parameter)
class Company def self.find(id) id endendcompany_id = 1classname = 'Company'object = Kernel.const_get(classname)object.send(:find, company_id)Company.find(company_id)
# 最后两行代码从作用上而言是完全等价的# 但是其编程实现方法是完全不同的# 好比数学上的函数与泛函的相似概念
【实 × 新 × 奇】http://www.lycom.de/ 最新报道Ruby语言、Rails框架、Ubuntu、MacOSX和软件技术信息
订阅 full-text RSS 或者 comments RSS.
Interesting links can be found at del.icio.us or by subscribing to my del.icio.us feed
Powered by SimpleLog