module Test
def self.model_method
puts "this is a module method"
end
end
class A
include Test
end
A.model_method
と、このなりますエラー:モジュールの '自己'メソッドがなぜクラスのシングルトンメソッドになれないのですか?
未定義のメソッドのための `model_method」:クラス(NoMethodError)
しかし、私はAのメタクラスを使用した場合、それは動作します:
module Test
def model_method
puts "this is a module method"
end
end
class A
class << self
include Test
end
end
A.model_method
誰かがこれを説明できますか?
が重複する可能性が[?モジュールでクラスメソッドを定義することは可能です](http://stackoverflow.com/questions/4699355/is-that-possible-to-define -a-class-method-in-a-module) –