Friday, May 30, 2008

Ruby Predefined Constants/Variables

Constants
ENV # Hash of environment variables
STDIN # IO stream for standard input
STDOUT # IO stream for standard output, most cases the console
STDERR # IO stream for standard error output
RUBY_VERSION # String containing current ruby version
RUBY_RELEASE_DATE # String containing the date in which ruby was compiled
RUBY_PLATFORM # String containing the platform and compiler used to build ruby
ARGV # Array of arguments used to run the ruby file. ARGV[0] is the first argument, not the name of the file.


Variables
$: # Ruby Include Path
$> # STDOUT
$. # Current Line
$! # 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
$SAFE # safe level (0-4)
$" # Loaded modules, extensions (also $LOADED_FEATURES)

No comments: