我正在尝试定义一些模块,以便轻松地向其他类添加一些实例方法和类方法,这是我的代码:
module Foo
module Bar
def speak
puts "hey there"
end
end
module Baz
extend Foo::Bar
def welcome
puts "welcome, this is an instance method"
end
end
end
class Talker
include Foo::Baz
end
Talker.new.welcome
Talker.speak
这的输出结果是:welcome, this is an instance method
undefined method 'speak' for Talker.class (NoMethodError)
我原本期望Talker有'speak'方法,因为它包含了扩展了Foo::Bar的Foo::Baz类。
我漏掉了什么?