令牌“$$”在Ruby中意味着什么?

时间:2011-07-09 14:13:02

标签: ruby minimagick

我在mini_magick库的makeTempname()中的image_temp_file.rb中看到了这个变量。

3 个答案:

答案 0 :(得分:5)

$开始引用全局变量。程序通常会定义类似 $ name 的内容,系统会预定义许多信息和控件引用。

$$ ,特别是进程ID。

 
    $name program-defined global variable
    $!  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

答案 1 :(得分:4)

这是运行您所在脚本的Ruby解释器的进程ID。例如:

[/tmp] Ψ irb
ruby> $$
 => 16045                          # We're in process id 16045.
ruby> ^Z
[1]+  Stopped irb                  # Let's stop irb so we can
                                   # verify that it's the right pid.

[/tmp] Ψ ps aux | grep -inr 16045  # grep across all processes.
80:johnf    16045  ... irb         # There it is!

答案 2 :(得分:0)

$$计算正在运行的程序的进程ID。