【发布时间】:2011-10-13 14:02:29
【问题描述】:
我有一个模块,里面有一个类变量
module Abc
@@variable = "huhu"
def self.get_variable
@@variable
end
class Hello
def hola
puts Abc.get_variable
end
end
end
a = Abc::Hello.new
a.hola
是否可以在不使用get_variable 方法的情况下在Hello 中获取@@variable?我的意思是像Abc.variable 这样的东西会很好。只是好奇。
【问题讨论】:
标签: ruby accessor class-variables