On Sun, 2011-04-03 at 09:30 +0900, Stefan Salewski wrote:
> Can I define a variable in a module, and access and redefine it later?
OK, this is very close to my desire:
module Gravity
#def initialize()
@g = 9.81
#end
def self.get()
@g
end
def self.set(g)
@g = g
end
end
puts Gravity::get()
Gravity.set(9.8102) # we have done a more precice measurement
puts Gravity.get()
This gives output
stefan@AMD64X2 ~/pet $ ruby hhh.rb
9.81
9.8102
Is there something like attr_accessor for modules, allowing writing
something like g=9.8102 and puts g instead of set and get methods?