Back

Ruby中的罕见变量( rarely seen variables in Ruby)

发布时间: 2012-09-04 07:19:00

今天看到了几个比较罕见的RUBY变量,所以记录下来: ( Today I met the $name variable in Ruby which is rarely seen to me, so I made a memoranda here)

$,    A global variable, e.g. $codes = [200, 300]
@,  An instance variable, e.g.  @name = "joey"
[a-z] or _, 	A local variable,  e.g. var = 30
[A-Z], A constant, e.g. RED = 'red'
@@	A class variable, e.g. @@action = :say
下面是一些系统定义好的变量: ( below are some predefined variables )
$@ 	The location of latest error
$_ 	The string last read by gets
$. 	The line number last read by interpreter
$& 	The 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])
$= 	The case-insensitivity flag
$/ 	The input record separator
$\ 	The output record separator
$0 	The name of the ruby script file currently executing
$* 	The command line arguments used to invoke the script
$$ 	The Ruby interpreter's process ID
$? 	The exit status of last executed child process

Back