There is a collection of special variables whose names consist of a dollar sign ($) followed by a single character. For example, $$ contains the process id of the ruby interpreter, and is read-only.
$
global variable
@
instance variable
[a-z] or _
local variable
[A-Z]
constant
Here are the major system variables:
$!
latest error message
$@
location of error
$_
string last read by gets
$.
line number last read by interpreter
$&
string last...
There is a collection of special variables whose names consist of a dollar sign ($) followed by a single character. For example, $$ contains the process id of the ruby interpreter, and is read-only.
$
global variable
@
instance variable
[a-z] or _
local variable
[A-Z]
constant
Here are the major system variables:
$!
latest error message
$@
location of error
$_
string last read by gets
$.
line number last read by interpreter
$&
string last matched by regexp
$~
the last regexp match, as an array of subexpressions
$n
the nth subexpression in the last match (same as $~[n])
$=
case-insensitivity flag
$/
input record separator
$\
output record separator
$0
the name of the ruby script file
$*
the command line arguments
$$
interpreter's process ID
$?
exit status of last executed child process
In the above, $_ and $~ have local scope. Their names suggest they should be global, but they are much more useful this way, and there are historical reasons for using these names.
View more