Dlaczego metoda modułu „ja” nie może stać się pojedynczą metodą klasy?
module Test
def self.model_method
puts "this is a module method"
end
end
class A
include Test
end
A.model_method
będzie to błąd z:
niezdefiniowana metoda `model_method 'dla A: Class (NoMethodError)
Ale kiedy używam metaklasy A. dział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
Czy ktoś może to wyjaśnić?