【发布时间】:2011-07-06 10:26:53
【问题描述】:
我在 ruby 文档中看到了 module_function 中的示例。我不明白 Mod.one 返回旧的“这是一个”而 c.one 返回更新的“这是新的”的代码的后半部分。这是怎么回事
这是文档中的实际代码
module Mod
def one
"This is one"
end
module_function :one
end
class Cls
include Mod
def call_one
one
end
end
Mod.one #=> "This is one"
c = Cls.new
c.call_one #=> "This is one"
module Mod
def one
"This is the new one"
end
end
Mod.one #=> "This is one"
c.call_one #=> "This is the new one"
为什么 Mod.one 返回旧代码但 Cls 对象能够访问新代码? 谢谢。
【问题讨论】:
-
我打算将
callOne编辑为call_one,但您在文档中注意到它是这样的。我会在某个阶段提交一份关于此问题的错误报告。
标签: ruby ruby-1.9.1