:disabled, ->{ where(disabled: true) } end end module ClassMethods ... end end module M extend ActiveSupport::Concern included do scope :disabled, ->{ where(disabled: true) } end class_methods do ... end end $PODFSOͳ͠ $PODFSO͋Γ w ΫϥεϝιουͷՃJODMVEFͨ͠ଆͷΫϥεϝιουͷݺͼग़͠Λ؆ ୯ʹॻ͚Δ
m1_class_method 'M1!' end end end module M2 include M1 def self.included(base) base.extend(ClassMethods) end module ClassMethods def m2_class_method m1_class_method + ' M2!' end end end class C include M2 end C.m2_class_method #=> NameError: undefined local variable or method `m1_class_method' for C:Class $PODFSOͳ͠ w JODMVEF͢ΔϞδϡʔϧͷґଘؔΛཧͯ͘͠ΕΔ module M1 extend ActiveSupport::Concern class_methods do def m1_class_method 'M1!' end end end module M2 extend ActiveSupport::Concern include M1 class_methods do def m2_class_method m1_class_method + ' M2!' end end end class C include M2 end C.m2_class_method #=> "M1! M2!" $PODFSO͋Γ
JODMVEFEʹͨ͠ϒϩοΫΛJODMVEFͨ͠ଆͷΫϥεͷίϯςΩετͰ࣮ߦ͢Δ def append_features(base) if base.instance_variable_defined?(:@_dependencies) base.instance_variable_get(:@_dependencies) << self return false else return false if base < self @_dependencies.each { |dep| base.include(dep) } super base.extend const_get(:ClassMethods) if const_defined?(:ClassMethods) base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block) end end
raise MultipleIncludedBlocks if instance_variable_defined?(:@_included_block) @_included_block = block else super end end def class_methods(&class_methods_module_definition) mod = const_defined?(:ClassMethods, false) ? const_get(:ClassMethods) : const_set(:ClassMethods, Module.new) mod.module_eval(&class_methods_module_definition) end $MBTT.FUIPETϞδϡʔϧʹDMBTT@NFUIPETʹ͞ΕͨϒϩοΫͷ ༰ΛՃ͢Δ