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?
Variables must be declared in most languages in order to specify their type, modifiability (i.e., whether they are constants), and scope; since type is not an issue, and the rest is evident from the variable name as you are about to see, we do not need variable declarations in ruby.
Ruby Local Variables When an uninitialized local variable is referenced, it is interpreted as a call to a method that has no arguments. Assignment to uninitialized local variables also serves as variable declaration. The variables start to exist until the end of the current scope is reached.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With