Avoiding global variables, most of the time
Global variables are available in Ruby, but in general, their use is discouraged unless it is necessary. Some examples where it may make sense for you to use global variables are when you are modifying the load path:
$LOAD_PATH.unshift("../lib")
Or when you are silencing warnings in a block (assuming you actually have a good reason to do that):
def no_warnings verbose = $VERBOSE $VERBOSE = nil yield ensure $VERBOSE = verbose end
Or lastly, when reading/writing to the standard input, output, or error:
$stdout.write($stdin.read) rescue $stderr.puts($!.to_s)
These are all cases where you are using the existing global variables. It rarely makes sense to define and use your own global variables, even though Ruby does make it easy to use global variables since they are global and available everywhere.
The main issues with using global variables in Ruby are the same as...