Tuesday, September 10, 2013

Ruby Predefined Variables

This is a list of the frequently used predefined variables in ruby:

Exceptions
$! message of the last exception
$@ backtrace of the last exception

Regexp
$& the string that matched the last last regexp match
$` string preceding $&
$’ string following $&
$+ last parentheses match
$1, $2, $3… parentheses matches
$~ MatchData object containing information about the last match
$= case insensitive flag

Separators
$/ used by gets, readline etc. as a separator (defaults to “\n”)
$\ used by print, write etc. as a separator (defaults to nil)
$, used by Array#join
$; used by String#split

IO
$< program input
$> program output
$stdin standard input
$stdout standard output
$stderr standard error output
$. line number of the last read file
$_ last input line - used by gets, readline

Process
$0 program name
$* command line arguments
$$ PID of the program
$? exit status of the last process
$: $LOAD_PATH
$” all filenames required by the script
$SAFE security level 0-4, 0 having no restrictions and being the default
$DEBUG debugger enabled?

No comments:

Post a Comment

Please include your thoughts/suggestion to make it as a better blog. If you find it useful, Please update with your valuable comments, so that others can use it.