更新时间:2023-02-16 23:32:31
使用const_missing
挂钩.如果在当前模块中找不到该常量,请尝试在全局名称空间中进行解析:
Use the const_missing
hook. If the constant can't be found in the current module, try to resolve in the global namespace:
class A; end
class B; end
module M
def self.const_missing(c)
Object.const_get(c)
end
end
M::A.new
M::B.new