What are the magic $-prefixed variables in Ruby? [closed]

I've seen magic variables like this used in Ruby. $_ $' $0

Is there a complete reference for what all of them mean and how they are set?


Their name is global variables. There are several different references.

You can get a full list by calling the method Kernel#global_variables

puts global_variables

Ruby also includes a file called "English.rb" in the standard library which provides an in-depth explanation of several global variables.

Also, there's (an archived version of) "Cryptic Ruby Global Variables and Their Meanings".

Finally, the Ruby Programming wikibook has a "Predefined Variables" reference.


They are called "global variables" (complete list at the bottom of the page): http://www.rubyist.net/~slagell/ruby/globalvars.html


The Ruby documentation used to be very class orientated. In recent versions of Ruby however there are rdoc files about literals, precedence, syntax, globals and much more.