【发布时间】:2016-09-08 13:29:34
【问题描述】:
我正在试验 Ruby include 关键字,如下所示:
module A
def show
puts "working"
end
end
include A
class E
end
class D
end
e = E.new
d = D.new
e.show
d.show
o = Object.new
puts o.respond_to?("show")
******************************output****************
working
working
true
我期待输出是undefined method,但它给了我正确的输出。我还观察到module A 中定义的show 方法正在成为Object 的实例方法。
为什么这些方法会成为Object 类的实例方法?
请帮助理解这个概念。
【问题讨论】:
标签: ruby