Tutorial by Examples

Is the relative path to the file from the current execution directory Assume we have this directory structure: /home/stackoverflow/script.rb script.rb contains: puts __FILE__ If you are inside /home/stackoverflow and execute the script like ruby script.rb then __FILE__ will output script.rb ...
__dir__ is not a constant but a function __dir__ is equal to File.dirname(File.realpath(__FILE__))
Contains the name of the script being executed. Is the same as __FILE__ if you are executing that script.

$$

The process number of the Ruby running this script
Contains the subpattern from the corresponding set of parentheses in the last successful pattern matched, not counting patterns matched in nested blocks that have been exited already, or nil if the last pattern match failed. These variables are all read-only.
Command line arguments given for the script. The options for Ruby interpreter are already removed.
The standard input. The default value for $stdin
The standard output. The default value for $stdout
The standard error output. The default value for $stderr
The current standard error output.
The current standard output
The current standard input

ENV

The hash-like object contains current environment variables. Setting a value in ENV changes the environment for child processes.

Page 1 of 1