Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
Is there a named method equivalent to $? in Ruby?

In Ruby, I'd like to access the status of the most recently executed external command's result information, that is, the information provided by $?, but would prefer a named method or variable. Is there such a thing, and, if so, how do I access it?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Process.last_status returns the same Process::Status instance as $?:

$ irb
> `ls 12341234`
ls: 12341234: No such file or directory
 => ""
> $? == Process.last_status
 => true
> $?.equal? Process.last_status
 => true
> $?.class
 => Process::Status

Thread Local

Also, this variable is thread local, so each thread will have its own variable (i.e. threads will not overwrite a single global value). From the docs at https://ruby-doc.org/core-2.5.0/Process.html#method-c-last_status:

"Returns the status of the last executed child process in the current thread."

over 4 years ago · Santiago Trujillo Report

0

would prefer a named […] variable.

The English standard library provides descriptive aliases for $? and other special global variables. But unlike Process.last_status this library has be loaded before any of its aliases can be used. The upside is it exists in Ruby < 2.5.

$ irb -rEnglish
> `ls 12341234`
ls: 12341234: No such file or directory
 => ""
> $? == CHILD_STATUS
 => true
> $?.equal? CHILD_STATUS
 => true
> $?.class
 => Process::Status
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!