What is the meaning of $$ in Ruby?

前端 未结 5 2015
囚心锁ツ
囚心锁ツ 2021-02-19 08:19
irb(main):002:0> $$
=> 5052

What is the meaning of $$ in Ruby and How/Where to use it?

相关标签:
5条回答
  • 2021-02-19 08:44

    It's the process ID of the Ruby interpreter. $ is a prefix for global variables, see here for a list.

    0 讨论(0)
  • 2021-02-19 08:45

    This seems like a good reference for stuff like this...has a lot of symboly goodness.

    0 讨论(0)
  • 2021-02-19 08:52
    pipe = IO.popen("")
    if pipe
      STDERR.puts "In parent, child pid is #{pipe.pid}"
    else
      STDERR.puts "In child, pid is #{$$}"
    end
    

    This example shows how the process ID can be used. Process ID is part of 'Execution Environment Variables' (part of predifined variables).

    0 讨论(0)
  • 2021-02-19 08:53

    $$ is the process ID. It's named that way to follow Perl, which in turn followed the Bourne shell; both of them also use $$ in the same way.

    0 讨论(0)
  • 2021-02-19 08:53

    It's the process ID of the current Ruby process. Read-only

    0 讨论(0)
提交回复
热议问题