Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda