Method: Kernel#at_exit
- Defined in:
- eval.c
#at_exit { ... } ⇒ Proc
Converts block to a Proc object (and therefore binds it at the point of call) and registers it for execution when the program exits. If multiple handlers are registered, they are executed in reverse order of registration.
def do_at_exit(str1)
at_exit { print str1 }
end
at_exit { puts "cruel world" }
do_at_exit("goodbye ")
exit
produces:
goodbye cruel world
8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 |
# File 'eval.c', line 8052
static VALUE
rb_f_at_exit()
{
VALUE proc;
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "called without a block");
}
proc = rb_block_proc();
rb_set_end_proc(call_end_proc, proc);
return proc;
}
|