summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-09 15:34:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-09 15:34:30 +0000
commit7a330ba230833b2a3215012808b6fb2ce57722cf (patch)
tree41fff657670251d2ea1af57633666046b896cd51
parentbcb4075d9a8e78a63e773a0deb367d902f6bdfa8 (diff)
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
-rw-r--r--gc.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/gc.c b/gc.c
index 55e2153..178d52e 100644
--- a/gc.c
+++ b/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);
}