ActiveSupport::Concern
有an article掛鉤。下面是Rails的一個工作實施:ActiveSupport :: Concern vs append_features
module ActionController
class Base < Metal
include AbstractController::Layouts
end
end
module AbstractController
module Layouts
extend ActiveSupport::Concern
include Rendering
included do
class_attribute :_layout, :_layout_conditions, :instance_accessor => false
self._layout = nil
self._layout_conditions = {}
_write_layout_method
end
module ClassMethods
...
end
end
end
module AbstractController
module Rendering
extend ActiveSupport::Concern
included do
class_attribute :protected_instance_variables
self.protected_instance_variables = []
end
module ClassMethods
...
end
end
end
是如何extend
呼叫Layouts
的append_features
紅寶石掛鉤之前執行?必須先執行extend
。畢竟,它的全部重點是劫持默認的append_features
並重新實現它。但是,根據Ruby文檔,append_features
在將此模塊(例如AbstractController::Layouts
)包含在另一個模塊(例如ActionController::Base
)中後立即執行。所以這裏對我來說很混亂。如果是這種情況,那麼ActiveSupport::Concern
的覆蓋append_features
將永遠不會被調用。