代码如下
module M
def define_keys(*keys)
define_method :hello do
keys += [:hello,:bye]
end
end
end
class A
extend M
define_keys :nihao
end
a = A.new
p a.hello
#output [:nihao, :hello, :bye]
p a.hello
#output [:nihao, :hello, :bye, :hello, :bye]
p a.hello
#output [:nihao, :hello, :bye, :hello, :bye, :hello, :bye]
b = A.new
p b.hello
#output [:nihao, :hello, :bye, :hello, :bye, :hello, :bye, :hello, :bye]
一开始以为每次的结果都应该一样的,不太懂啊