问题描述
|
我有以下结构:
module SomeMod::SubMod
module Mod1; end
module Mod2; end
end
我想获取SubMod的所有常量,但是我想要对常量的完全限定引用(即a1 qualified)。目前,我正在这样做:
SomeMod::SubMod.constants.map{ |constant| SomeMod::SubMod.const_get constant }
有人可以改善吗?我可以删除对“ 3”的重复引用吗?
解决方法
SomeMod::SubMod.module_eval{ constants.map{|c| const_get c} }
不过,它实际上并没有那么短。