我有一个如下所示的类:
class Foo
MY_CONST = "hello"
ANOTHER_CONST = "world"
def self.get_my_const
Object.const_get("ANOTHER_CONST")
end
end
class Bar < Foo
def do_something
avar = Foo.get_my_const # errors here
end
end
得到一个const_get uninitialized constant ANOTHER_CONST (NameError)
假设我只是在 Ruby 范围内做一些愚蠢的事情。我目前正在测试此代码的机器上使用 Ruby 1.9.3p0。