APIdock / Ruby
/
method

exit

ruby latest stable - Class: Kernel
exit(*args)
public

Initiates the termination of the Ruby script by raising the SystemExit exception. This exception may be caught. The optional parameter is used to return a status code to the invoking environment. true and FALSE of status means success and failure respectively. The interpretation of other integer values are system dependent.

begin
 exit 
 puts  "never get here"
rescue SystemExit 
 puts  "rescued a SystemExit exception"
end
puts  "after begin block"

produces:

rescued a SystemExit  exception
after begin block

Just prior to termination, Ruby executes any at_exit functions (see Kernel::at_exit) and runs any object finalizers (see ObjectSpace::define_finalizer).

at_exit  { puts  "at_exit function" }
ObjectSpace .define_finalizer("string", proc  { puts  "in finalizer" })
exit 

produces:

at_exit  function
in finalizer
VALUE
rb_f_exit(int argc, const VALUE *argv)
{
 int istatus;
 if (rb_check_arity(argc, 0, 1) == 1) {
 istatus = exit_status_code(argv[0]);
 }
 else {
 istatus = EXIT_SUCCESS;
 }
 rb_exit(istatus);
 UNREACHABLE;
}

AltStyle によって変換されたページ (->オリジナル) /