我有一個模塊在一個類變量它訪問模塊的類變量在類中使用Ruby
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
是否有可能得到@@variable
內Hello
不使用get_variable
方法?我的意思是像Abc.variable
會很好。只是好奇。
的[哪有Ruby的attr_accessor農產品類變量或類的實例變量而不是實例變量?](http://stackoverflow.com/questions/895747/how-can-可能重複ruby-attr -accessor -products-class-variables-or-class-instance-variables) –