令牌“$$”代表什么?在 Ruby 中是什么意思?

发布于 2024-11-19 03:34:21 字数 69 浏览 2 评论 0原文

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

I see this variable in image_temp_file.rb in makeTempname() in the mini_magick library.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不羁少年 2024-11-26 03:34:21

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

$$ 特别是进程 ID。

 
    $name program-defined global variable
    $!  latest error message
    $@  location of error
    $_  string last read by gets
    $.  line number last read by interpreter
    
amp;  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

The $ begins a reference to a global variable. Programs will typically define something like $name and the system predefines a number of information and control references.

$$, in particular, is the process 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
久光 2024-11-26 03:34:21

它是运行您所在脚本的 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!

It's the process ID of the Ruby interpreter running the script you're in. For example:

[/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!
好菇凉咱不稀罕他 2024-11-26 03:34:21

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

$$ evaluates to the process id of the running program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文