constantize()函数
来源:互联网 发布:java工程师年龄要求 编辑:程序博客网 时间:2024/06/05 02:07
constantize()Link
constantize
tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized. See ActiveSupport::Inflector#constantize
"Module".constantize() #=> Module
"Class".constantize() #=> Class
"blargle".constantize() #=>NameError: wrong constant name blargle
实例:
def get_room(p = {})
room = Room.find_by_id(p[:room_id])
if room.present?
ic = ItemCorrelation.find_by(source_id: room.id, source_type: room.class.name, role: ROLE)
if ic.present?
for_who = ic.for_who
"Agent::#{for_who.classify}::Room".constantize.get_room(p)
end
end
end
0 0
- constantize()函数
- rails或者rails的engine中model模块化以及constantize使用
- rails或者rails的engine中model模块化以及constantize使用
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 大话设计模式13----建造者模式
- 【bzoj3611】 大工程
- 杭电5562之Clarke and food
- 非空子集个数
- wireshark捕获/过滤指定ip地址数据包
- constantize()函数
- Graham求凸包
- POJ 3450 Corporate Identity(kmp求多个字符串的最长公共子串)
- [HDU 2222] Keywords Search [AC自动机]
- 剑指offer 37题 【时间空间效率的平衡】两个链表的第一个公共结点
- 二、词法结构
- ISO12233分辨率测试卡的使用方法
- tjut 4920
- ubuntu14.04搭建hadoop集群