我讀到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