I’m trying to use my variable in all files of my program.
this is an example of what I’m trying to do.
main.rb
Class1
def self.test1
puts "class 1" if @@debug
end
end
@@ debug = true
class.test1
class.test2
class2.rb
Class2
def self.test2
puts "test2" if @@debug
end
end
I really hope it’s enough clear for the community, any help would be appreciated, thanks!
You want a global variable or constant. You could create your own, but Ruby conveniently comes with a builtin
$DEBUGglobal variable. When you specify the-doption toruby,$DEBUGwill betrue, and otherwise,false.If the classes are in multiple files, put this in the file that includes the others:
And in the other files, use
DEBUGfor debug, rather than$DEBUG.