Method: Kernel#exit
- Defined in:
- process.c
#exit(status = true) ⇒ Object #exit(status = true) ⇒ Object
Initiates termination of the Ruby script by raising SystemExit; the exception may be caught. Returns exit status status
to the underlying operating system.
Values true
and false
for argument status
indicate, respectively, success and failure; The meanings of integer values are system-dependent.
Example:
begin
exit
puts 'Never get here.'
rescue SystemExit
puts 'Rescued a SystemExit exception.'
end
puts 'After begin block.'
Output:
Rescued a SystemExit exception.
After begin block.
Just prior to final termination, Ruby executes any at-exit procedures (see Kernel::at_exit) and any object finalizers (see ObjectSpace::define_finalizer).
Example:
at_exit { puts 'In at_exit function.' }
ObjectSpace.define_finalizer('string', proc { puts 'In finalizer.' })
exit
Output:
In at_exit function.
In finalizer.
4531 4532 4533 4534 4535 4536 |
# File 'process.c', line 4531
static VALUE
f_exit(int c, const VALUE *a, VALUE _)
{
rb_f_exit(c, a);
UNREACHABLE_RETURN(Qnil);
}
|