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