[前][次][番号順一覧][スレッド一覧]

ruby-changes:31540

From: nobu <ko1@a...>
Date: Sun, 10 Nov 2013 00:34:41 +0900 (JST)
Subject: [ruby-changes:31540] nobu:r43620 (trunk): gc.c: should_be_callable

nobu	2013-11-10 00:34:30 +0900 (Sun, 10 Nov 2013)

  New Revision: 43620

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43620

  Log:
    gc.c: should_be_callable
    
    * gc.c (should_be_callable): extract duplicate code.

  Modified files:
    trunk/gc.c
Index: gc.c
===================================================================
--- gc.c	(revision 43619)
+++ gc.c	(revision 43620)
@@ -1863,6 +1863,15 @@ rb_undefine_final(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L1863
     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, VALU https://github.com/ruby/ruby/blob/trunk/gc.c#L1891
     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 https://github.com/ruby/ruby/blob/trunk/gc.c#L1930
 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);
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]