mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
bcb4075d9a
commit
7a330ba230
1 changed files with 12 additions and 7 deletions
19
gc.c
19
gc.c
|
@ -1863,6 +1863,15 @@ rb_undefine_final(VALUE obj)
|
||||||
return 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:
|
* call-seq:
|
||||||
* ObjectSpace.define_finalizer(obj, aProc=proc())
|
* ObjectSpace.define_finalizer(obj, aProc=proc())
|
||||||
|
@ -1882,9 +1891,8 @@ define_final(int argc, VALUE *argv, VALUE os)
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
block = rb_block_proc();
|
block = rb_block_proc();
|
||||||
}
|
}
|
||||||
else if (!rb_respond_to(block, rb_intern("call"))) {
|
else {
|
||||||
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
should_be_callable(block);
|
||||||
rb_obj_classname(block));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return define_final0(obj, block);
|
return define_final0(obj, block);
|
||||||
|
@ -1922,10 +1930,7 @@ VALUE
|
||||||
rb_define_final(VALUE obj, VALUE block)
|
rb_define_final(VALUE obj, VALUE block)
|
||||||
{
|
{
|
||||||
rb_check_frozen(obj);
|
rb_check_frozen(obj);
|
||||||
if (!rb_respond_to(block, rb_intern("call"))) {
|
should_be_callable(block);
|
||||||
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
|
||||||
rb_obj_classname(block));
|
|
||||||
}
|
|
||||||
return define_final0(obj, block);
|
return define_final0(obj, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue