module Test
def self.model_method
puts "this is a module method"
end
end
class A
include Test
end
A.model_method
これは次のエラーになります。
A:Class の未定義メソッド「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
誰かがこれを説明できますか?