我有一个这样的模块:
module Controller
module LocaleModels
def self.included(base)
base.send :include, InstanceMethods
end
module InstanceMethods
def locale_Lexeme; constantize_model('Lexeme') end
def locale_Synthetic; constantize_model('Synthetic') end
def locale_Property; constantize_model('Property') end
private
def constantize_model(common_part)
eval(I18n.locale.capitalize + '::' + common_part).constantize
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
但我一直在努力
NoMethodError (undefined method `constantize' for #<Class:0x2483b0c>)
Run Code Online (Sandbox Code Playgroud)
我想我不能在自定义模块中使用'constantize'.
但是,请你提供一些解决方法吗?