Ruby预定义全局变量

Ruby预定义全局变量
2011-05-09 14:59

Ruby's predefined (built-in) variables affect the behavior of the entire program, so their use in libraries isn't recommended. The values in most predefined variables can be accessed by alternative means.

$!

The last exception object raised. The exception object can also be accessed using => in rescue clause.

$@

The stack backtrace for the last exception raised. The stack backtrace information can retrieved by Exception#backtrace method of the last exception.

$/

The input record separator (newline by default). gets, readline, etc., take their input record separator as optional argument.

$\

The output record separator (nil by default).

$,

The output separator between the arguments to print and Array#join (nil by default). You can specify separator explicitly to Array#join.

$;

The default separator for split (nil by default). You can specify separator explicitly for String#split.

$.

The number of the last line read from the current input file. Equivalent to ARGF.lineno.

$<

Synonym for ARGF.

$>

Synonym for $defout.

$0

The name of the current Ruby program being executed.

$$

The process.pid of the current Ruby program being executed.

$?

The exit status of the last process terminated.

$:

Synonym for $LOAD_PATH.

$DEBUG

True if the -d or --debug command-line option is specified.

$defout

The destination output for print and printf ($stdout by default).

$F

The variable that receives the output from split when -a is specified. This variable is set if the -a command-line option is specified along with the -p or -n option.

$FILENAME

The name of the file currently being read from ARGF. Equivalent to ARGF.filename.

$LOAD_PATH

An array holding the directories to be searched when loading files with the load and require methods.

$SAFE

The security level. See 

相关推荐