ruby的预定义变量

February 10, 2014

Some globals have actual readable names:

$DEBUG     # The boolean status of the -d switch.
$FILENAME  # Current input file from ARGF. Same as ARGF.filename.
$LOAD_PATH # Load path for scripts and binary modules by load or require.
$stderr    # The current standard error output.
$stdin     # The current standard input.
$stdout    # The current standard output.
$VERBOSE   # The verbose flag, which is set by the -v switch.
But most dont:

$!  # The exception object passed to #raise.
$@  # The stack backtrace generated by the last exception raised.
$&  # Depends on $~. The string matched by the last successful match.
$`  # Depends on $~. The string to the left of the last successful match.
$'  # Depends on $~. The string to the right of the last successful match.
$+  # Depends on $~. The highest group matched by the last successful match.
$1  # Depends on $~. The Nth group of the last successful match. May be > 1.
$~  # The MatchData instance of the last match. Thread and scope local. MAGIC
$=  # The flag for case insensitive. Defaults to nil. Deprecated.
$/  # The input record separator (eg #gets). Defaults to newline.
$\  # The output record separator (eg #print and IO#write). Default is nil.
$,  # The output field separator for the print and Array#join. Defaults to nil.
$;  # The default separator for String#split. See -F flag.
$.  # The current line number of the last file from input.
$<  # See ARGF.
$>  # The default output for print, printf. Defaults to $stdout.
$_  # The last input line of string by gets or readline. Thread and scope local.
$0  # Contains the name of the script being executed. May be assignable.
$*  # See ARGV.
$$  # The process number of the Ruby running this script. Read only.
$?  # The status of the last executed child process. Read only. Thread local.
$:  # See $LOAD_PATH.
$"  # The array contains the module names loaded by require.

Many command line arguments have an associated global, which is usually just an alias to a real global:

$-0  # See $/.
$-a  # Autosplit mode. True if option -a is set. Read-only variable.
$-d  # See $DEBUG.
$-F  # See $;.
$-i  # In in-place-edit mode, this variable holds the extension, otherwise nil.
$-I  # See $LOAD_PATH.
$-l  # True if option -l is set. Read-only.
$-p  # True if option -p is set. Read-only.
$-v  # See $VERBOSE.
$-w  # True if option -w is set.

http://www.zenspider.com/Languages/Ruby/QuickRef.html

【译】APP索引&SEO的下一个战场:苹果搜索 + iOS APP索引

译者定义:1. 应用页面 的原文叫“app screen”,相当于一个网页,比如你在看知乎APP中的一篇帖子,那么这个帖子就是一个“应用页面”。2. TDK的意思是“标题 描述 关键词”============================================...… Continue reading