我读到ActiveSupport :: Concern的API。有ClassMethods
和InstanceMethods
,我们可以把类方法放在ClassMethods
。为什么我们需要ClassMethods和InstanceMethods?
但是M
的主机可以使用M
中定义的方法,不是吗?为什么我不能只是写:
module M
def self.x
end
def y
end
end
而不是:
module M
module ClassMethods
def x
end
end
module InstanceMethods
def y
end
end
end