Ruby: List of Predefined Global Variables
require "English" | Variable | Meaning |
---|---|---|
◇ | $0 | name of the Ruby script file currently executing |
$ARGV | $* | An array of strings containing the command-line options from the invocation of the program. Options used by the Ruby interpreter will have been removed. Read only. Also known simply as +ARGV+. |
$LOADED_FEATURES | ◇ | ◇ |
◇ | $: | Load path for scripts and binary modules by load or require. |
require "English" | Variable | Meaning |
---|---|---|
$ERROR_INFO | $! | The exception object passed to +raise+ |
$ERROR_POSITION | $@ | The stack backtrace generated by the last exception. See Kernel.caller for details. Thread local. |
$FS or $FIELD_SEPARATOR | $; | The default separator pattern used by String.split . May be set from the command line using the -F flag. |
$OFS or $OUTPUT_FIELD_SEPARATOR | $, | The separator string output between the parameters to methods such as Kernel.print and Array.join . Defaults to +nil+, which adds no text. |
$RS or $INPUT_RECORD_SEPARATOR | $/ | The input record separator (newline by default). This is the value that routines such as Kernel.gets use to determine record boundaries. If set to +nil+, +gets+ will read the entire file. |
$ORS or $OUTPUT_RECORD_SEPARATOR | $\ | The string appended to the output of every call to methods such as Kernel.print and IO.write . The default value is +nil+. |
$NR or $INPUT_LINE_NUMBER | $. | The number of the last line read from the current input file. |
$LAST_READ_LINE | $_ | The last line read by Kernel.gets or Kernel.readline . Many string-related functions in the +Kernel+ module operate on $_ by default. The variable is local to the current scope. Thread local. |
$DEFAULT_OUTPUT | $> | The destination of output for Kernel.print and Kernel.printf . The default value is $stdout . |
$DEFAULT_INPUT | $< | An object that provides access to the concatenation of the contents of all the files given as command-line arguments, or $stdin (in the case where there are no arguments). $< supports methods similar to a +File+ object: +inmode+, +close+,closed? , +each+,each_byte , each_line , +eof+, eof? , +file+, +filename+, +fileno+, +getc+, +gets+, +lineno+,lineno= , +path+, +pos+, pos= , +read+, +readchar+, +readline+, +readlines+, +rewind+, +seek+, +skip+, +tell+, to_a , to_i ,to_io , to_s , along with the methods in +Enumerable+. The method +file+ returns a +File+ object for the file currently being read. This may change as $< reads through the files on the command line. Read only. |
$PID or $PROCESS_ID | $$ | The process number of the program being executed. Read only. |
$CHILD_STATUS | $? | The exit status of the last child process to terminate. Read only. Thread local. |
Regex Match
require "English" | Variable | Meaning |
---|---|---|
$IGNORECASE | $= | If set to any value apart from +nil+ or +false+, all pattern matches will be case insensitive, string comparisons will ignore case, and string hash values will be case insensitive. Deprecated |
$LAST_MATCH_INFO | $~ | A +MatchData+ object that encapsulates the results of a successful pattern match. The variables $& , $` , $' , and $1 to $9 are all derived from $~ . Assigning to $~ changes the values of these derived variables. This variable is local to the current scope. Thread local. |
$MATCH | $& | The string matched by the last successful pattern match. This variable is local to the current scope. Read only. Thread local. |
$PREMATCH | $` | The string preceding the match in the last successful pattern match. This variable is local to the current scope. Read only. Thread local. |
$POSTMATCH | $' | The string following the match in the last successful pattern match. This variable is local to the current scope. Read only. Thread local. |
$LAST_PAREN_MATCH | $+ | The contents of the highest-numbered group matched in the last successful pattern match. Thus, in "cat" =~ /(c|a)(t|z)/ , $+ will be set to "t". This variable is local to the current scope. Read only. Thread local. |
misc
Where in the doc are those predefined vars?
in Ruby 2, it's documented at http://ruby-doc.org/core-2.0/doc/globals_rdoc.html .
for Ruby 1.9.3, it's not really documented. The closest is http://www.ruby-doc.org/stdlib-1.9.3/libdoc/English/rdoc/Object.html but the doc is empty.
You might read the file. Do print $:
to locate the search path. Then, search for file English.rb
.
- If you read the file
English.rb
, you see the use of$LOADED_FEATURES
, but that isn't defined in the file. - Also, the file doesn't contain
$:
, which is supposedly the lib search path.
Reference: /usr/lib/ruby/1.9.1/English.rb