Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda