Ruby/Language Basics/Predefined Variables
Материал из Wiki.crossplatform.ru
(Различия между версиями)
ViGOur (Обсуждение | вклад) м (1 версия: Импорт выборки материалов по Ruby) |
Текущая версия на 17:59, 13 сентября 2010
Predefined Variables list
variable Description $! last exception raised. Access with => in a rescue clause. $@ Stack backtrace of the last exception, retrievable via Exception#backtrace. $& String matched by the last successful pattern match, or nil if the last pattern match failed. Read only. Local. $" String preceding what was matched by the last successful pattern match, or nil if the last pattern match failed. Same as m.pre_match where m is a MatchData object. Read only. Local. $" String following what was matched by the last successful pattern match, or nil if the last pattern match failed. Same as m.post_match where m is a MatchData object. Read only. Local. $+ Last bracket matched by the last successful search pattern, or nil if the last pattern match failed. Read only. Local. $1, $2... Subpattern from the corresponding set of parentheses in the last successful pattern matched, or nil if the last pattern match failed. Same as m[n] where m is a MatchData object. Read only. Local. $~ Information about the last match in the current scope. Regex#match returns the last match information. Setting this variable affects match variables like $&, $+, $1, $2, etc. The nth subexpression can be retrieved by $~[nth]. Local. $= Case-insensitive flag; nil by default. $/ Input record separator; newline by default. If it is set to nil, a whole file will be read at once. gets, readline, etc., take the input record separator as an optional argument. $\ Output record separator for print and IO#write; nil by default. $, Output field separator between arguments; the default separator for Array#join. $; Default separator for String#split; nil by default. $. Input line number of the last file that was read. Same as ARGF.lineno. $< Virtual concatenation file of the files given by command-line arguments $<.filename returns the current filename. Synonym for ARGF. $> Default output for print, printf, and $stdout by default. Synonym for $defout. $_ Last input line of string by gets or readline in the current scope; set to nil if gets or readline meets EOF. Local. $0 Name of the current Ruby program being executed. $* Command-line arguments given for the script. The options for the Ruby interpreter are already removed. $$ Process number (process.pid) of the Ruby program being executed. $? Exit status of the last executed process. $: Synonym for $LOAD_PATH. $" Array containing the module names loaded by require. Used to prevent require from loading modules twice. $DEBUG True if -d or --debug switch is set. $defout Default output for print, printf, and $stdout by default. Synonym for $>. $F Receives output from split when -a is specified. Set if -a is set along with -p and -n. $FILENAME Name of the file currently being read from ARGF. Same as ARGF.filename or $<.filename. $LOAD_PATH Synonym for $:. $SAFE Security level: 0 No checks on externally supplied tainted data are allowed. 1 tainted data are forbidden. 2 files are forbidden. 3 All newly created objects are considered tainted. 4 Modification of global data is forbidden. $stdin standard input; STDIN by default. $stdout standard output; STDOUT by default. $stderr standard error output; STDERR by default. $VERBOSE True if verbose flag is set by the -v, -w, or --verbose switch of the Ruby interpreter. $-0 Alias of $/. $-a True if option -a is set. Read only. $-d Alias of $DEBUG. $-F Alias of $;. $-i In in-place-edit mode, holds the extension; otherwise nil. Can enable or disable in-place-edit mode. $-I Alias of $:. $-l True if option -lis is set. Read only. $-p True if option -pis is set. Read only.