I have a few .rb files and I want to use the same variables in all of them. Let’s say variable test_variable = "test" should be accessible from all my .rb files. How can I achieve that?
I created settings.rb file with test_variable = "test" then used require 'settings' in another .rb file, but it didn’t work. I would like to use require not load.
I tried to make the variable global by prefixing the variable name with $, but I am still getting undefined local variable or method 'test_variable' for main:Object (NameError).
Constants (which include modules and classes) are added to the shared global environment:
Instance variables declared in main are all part of the same
main:Global variables are also all part of the same environment (tested in 1.8.6, 1.8.7, and 1.9.2):