是否有等同于 $ 的命名方法?在 Ruby?
Is there a named method equivalent to $? in Ruby?
在Ruby中,我想访问最近执行的外部命令的结果信息的状态,即$?
提供的信息,但更喜欢命名方法或多变的。有没有这样的东西,如果有,我该如何访问它?
Process.last_status
returns 与 $?
:
相同的 Process::Status 实例
$ irb
> `ls 12341234`
ls: 12341234: No such file or directory
=> ""
> $? == Process.last_status
=> true
> $?.equal? Process.last_status
=> true
> $?.class
=> Process::Status
本地线程
此外,这个变量是线程局部变量,因此每个线程都有自己的变量(即线程不会覆盖单个全局值)。来自 https://ruby-doc.org/core-2.5.0/Process.html#method-c-last_status:
的文档
"Returns当前线程最后执行的子进程的状态。"
would prefer a named […] variable.
English
standard library provides descriptive aliases for $?
and other special global variables. But unlike Process.last_status
在可以使用其任何别名之前加载此库。好处是它存在于 Ruby < 2.5.
$ irb -rEnglish
> `ls 12341234`
ls: 12341234: No such file or directory
=> ""
> $? == CHILD_STATUS
=> true
> $?.equal? CHILD_STATUS
=> true
> $?.class
=> Process::Status
在Ruby中,我想访问最近执行的外部命令的结果信息的状态,即$?
提供的信息,但更喜欢命名方法或多变的。有没有这样的东西,如果有,我该如何访问它?
Process.last_status
returns 与 $?
:
$ irb
> `ls 12341234`
ls: 12341234: No such file or directory
=> ""
> $? == Process.last_status
=> true
> $?.equal? Process.last_status
=> true
> $?.class
=> Process::Status
本地线程
此外,这个变量是线程局部变量,因此每个线程都有自己的变量(即线程不会覆盖单个全局值)。来自 https://ruby-doc.org/core-2.5.0/Process.html#method-c-last_status:
的文档"Returns当前线程最后执行的子进程的状态。"
would prefer a named […] variable.
English
standard library provides descriptive aliases for $?
and other special global variables. But unlike Process.last_status
在可以使用其任何别名之前加载此库。好处是它存在于 Ruby < 2.5.
$ irb -rEnglish
> `ls 12341234`
ls: 12341234: No such file or directory
=> ""
> $? == CHILD_STATUS
=> true
> $?.equal? CHILD_STATUS
=> true
> $?.class
=> Process::Status