现有代码如下(代码有问题,就是我想解决的问题):
module M
def self.extended(klass)
klass::ROLES.each do |r|
define_method r do
puts klass::RESULTS[r]
end
end
end
end
class A
ROLES = [:a, :b]
RESULTS = {a: 1, b: 2}
extend M
end
class B
ROLES = [:a, :b]
RESULTS = {a: 3, b: 4}
extend M
end
期望结果: A.a #=> 1 A.b #=> 2 B.a #=> 3 B.b #=> 4 实际结果: A.a #=> 3 A.b #=> 4 B.a #=> 3 B.b #=> 4
求大神指教!