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 # from  www.jav  a 2 s .  co m
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.