我们可以在类的任何位置使用include
语句来包含模块吗?还是必须在类的开头进行声明?
如果我在类声明的开头包含模块,方法重载按预期工作。为什么如果我在结尾处包含它,它就不起作用呢?
# mym.rb
module Mym
def hello
puts "am in the module"
end
end
# myc.rb
class Myc
require 'mym'
def hello
puts "am in class"
end
include Mym
end
Myc.new.hello
=> am in class