我有一个类 Ryte::Theme。如果我在课堂上调用included_modules,我会回来(缩写):
[Ryte::Bundleable::Core、Ryte::Bundleable::Validators、Ryte::Bundleable::Builder、ActiveModel::Validations::HelperMethods、ActiveModel::Validations、ActiveSupport::Callbacks、Ryte::Bundleable]
Ryte::Theme 通过单个模块 Ryte::Bundleable 引入嵌套模块。以下是相关的类和模块定义:
class Ryte::Theme
include Ryte::Bundleable
end
module Ryte::Bundleable
extend ActiveSupport::Concern
included do
include ActiveModel::Validations
include Ryte::Bundleable::Builder
include Ryte::Bundleable::Validators
include Ryte::Bundleable::Core
end
end
鉴于此,为什么我会收到以下回复:
Ryte::Theme.include?(Ryte::Theme::Validators)
=> true
我还没有包含这个附加模块。这在 included_modules 响应中很明显。这与 ActiveSupport 关注有关吗?我希望能够包含 Ryte::Theme::Validators 并将其混入,但由于它认为它已经被包含,它不会“再次”包含它(如果这是真的,它不应该包含它)。因此,当我将包含添加到类定义中时,它会被遗忘,如下所示:
class Ryte::Theme
include Ryte::Bundleable
include Ryte::Theme::Validators # <- Does not load
end
为什么这个额外的模块 Ryte::Theme::Validators 也没有混合在一起?
添加
好的,刚刚意识到:
1.9.3p194 :005 > Ryte::Bundleable::Validators == Ryte::Theme::Validators
=> true
奇怪..这是为什么?