Ruby - Class Global Variables

Introduction

Ruby can use global variables.

Global variables are available from everywhere within an application, including inside classes or objects.

You define global variables by putting a dollar sign ($) in front of the variable name, like so:

Demo

def basic_method 
  puts $x # www .j  a v a  2 s  .c om
end 

$x = 10 
basic_method

Result

$x is defined as a global variable, and you can use it anywhere in your application.

The $ and @ characters that denote global variables and object variables are technically called sigils.