class SystemExit
由 exit 引发,以启动脚本的终止。
公共类方法
new → system_exit 点击以切换源代码
new(status) → system_exit
new(status, msg) → system_exit
new(msg) → system_exit
使用给定的状态和消息创建一个新的 SystemExit 异常。状态为 true、false 或一个整数。如果未给出状态,则使用 true。
static VALUE
exit_initialize(int argc, VALUE *argv, VALUE exc)
{
VALUE status;
if (argc > 0) {
status = *argv;
switch (status) {
case Qtrue:
status = INT2FIX(EXIT_SUCCESS);
++argv;
--argc;
break;
case Qfalse:
status = INT2FIX(EXIT_FAILURE);
++argv;
--argc;
break;
default:
status = rb_check_to_int(status);
if (NIL_P(status)) {
status = INT2FIX(EXIT_SUCCESS);
}
else {
#if EXIT_SUCCESS != 0
if (status == INT2FIX(0))
status = INT2FIX(EXIT_SUCCESS);
#endif
++argv;
--argc;
}
break;
}
}
else {
status = INT2FIX(EXIT_SUCCESS);
}
rb_call_super(argc, argv);
rb_ivar_set(exc, id_status, status);
return exc;
}
公共实例方法
status → integer 点击以切换源代码
返回与此系统退出相关的状态值。
static VALUE
exit_status(VALUE exc)
{
return rb_attr_get(exc, id_status);
}
success? → true or false 点击以切换源代码
如果退出成功,则返回 true,否则返回 false。
static VALUE
exit_success_p(VALUE exc)
{
VALUE status_val = rb_attr_get(exc, id_status);
int status;
if (NIL_P(status_val))
return Qtrue;
status = NUM2INT(status_val);
return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
}