S
Stefan Salewski
Can I define a variable in a module, and access and redefine it later?
Something like
module Gravity
G = 9.81
end
puts Gravity::G
Gravity::G = 9.8102 # we have done a more precise measurement
puts Gravity::G
works, but gives a warning. I have done some Google search and tried
instance and class variables for that module, but it does not work. My
goal: I have a module named Config with a configuration hash, with
predefined colors. I access that hash from other modules. That hash
should have default values, but it should be possible to redefine it.
(The other modules, which access that hash, are independent of each
other, none of then is special, so it is not really a good idea if one
of them has to define the initial hash content.) Currently I am using a
global variable for this purpose, called something like $Config_Colors.
Works fine, but I think I should use something related to my
configuration module, like Config::colors.
Best regards,
Stefan Salewski
Something like
module Gravity
G = 9.81
end
puts Gravity::G
Gravity::G = 9.8102 # we have done a more precise measurement
puts Gravity::G
works, but gives a warning. I have done some Google search and tried
instance and class variables for that module, but it does not work. My
goal: I have a module named Config with a configuration hash, with
predefined colors. I access that hash from other modules. That hash
should have default values, but it should be possible to redefine it.
(The other modules, which access that hash, are independent of each
other, none of then is special, so it is not really a good idea if one
of them has to define the initial hash content.) Currently I am using a
global variable for this purpose, called something like $Config_Colors.
Works fine, but I think I should use something related to my
configuration module, like Config::colors.
Best regards,
Stefan Salewski