From 7a330ba230833b2a3215012808b6fb2ce57722cf Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 9 Nov 2013 15:34:30 +0000 Subject: [PATCH] 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 --- gc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/gc.c b/gc.c index 55e2153dae..178d52e822 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); }