module Test
def self.model_method
puts "this is a module method"
end
end
class A
include Test
end
A.model_method
这将是错误的:
A:Class (NoMethodError) 的未定义方法“model_method”
但是当我使用 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
有人可以解释一下吗?