зеркало из https://github.com/github/ruby.git
gc.c: should_be_callable
* gc.c (should_be_callable): extract duplicate code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
bcb4075d9a
Коммит
7a330ba230
19
gc.c
19
gc.c
|
@ -1863,6 +1863,15 @@ rb_undefine_final(VALUE obj)
|
|||
return obj;
|
||||
}
|
||||
|
||||
static void
|
||||
should_be_callable(VALUE block)
|
||||
{
|
||||
if (!rb_respond_to(block, rb_intern("call"))) {
|
||||
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
||||
rb_obj_classname(block));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ObjectSpace.define_finalizer(obj, aProc=proc())
|
||||
|
@ -1882,9 +1891,8 @@ define_final(int argc, VALUE *argv, VALUE os)
|
|||
if (argc == 1) {
|
||||
block = rb_block_proc();
|
||||
}
|
||||
else if (!rb_respond_to(block, rb_intern("call"))) {
|
||||
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
||||
rb_obj_classname(block));
|
||||
else {
|
||||
should_be_callable(block);
|
||||
}
|
||||
|
||||
return define_final0(obj, block);
|
||||
|
@ -1922,10 +1930,7 @@ VALUE
|
|||
rb_define_final(VALUE obj, VALUE block)
|
||||
{
|
||||
rb_check_frozen(obj);
|
||||
if (!rb_respond_to(block, rb_intern("call"))) {
|
||||
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
||||
rb_obj_classname(block));
|
||||
}
|
||||
should_be_callable(block);
|
||||
return define_final0(obj, block);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче