Ruby program to access a global variable from a method of the class

bookmark

$global_var = 100;

class Sample
    def AcessGlobal
        print "global_var is: ",$global_var;
    end
end

obj = Sample.new();

obj.AcessGlobal();

 


Output:

global_var is: 100