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

ruby-changes:20809

From: nobu <ko1@a...>
Date: Fri, 5 Aug 2011 15:55:48 +0900 (JST)
Subject: [ruby-changes:20809] nobu:r32857 (trunk): * test/ruby/test_object.rb: tests that respond_to? returns false.

nobu	2011-08-05 15:55:36 +0900 (Fri, 05 Aug 2011)

  New Revision: 32857

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

  Log:
    * test/ruby/test_object.rb: tests that respond_to? returns false.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_object.rb
    trunk/vm_eval.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32856)
+++ ChangeLog	(revision 32857)
@@ -1,3 +1,7 @@
+Fri Aug  5 15:55:33 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* test/ruby/test_object.rb: tests that respond_to? returns false.
+
 Fri Aug  5 13:32:43 2011  Shugo Maeda  <shugo@r...>
 
 	* lib/xmlrpc/client.rb, lib/xmlrpc/server.rb: should use
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 32856)
+++ vm_eval.c	(revision 32857)
@@ -265,10 +265,12 @@
 static VALUE
 check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
 {
-    const rb_method_entry_t *me = rb_method_entry(CLASS_OF(recv), idRespond_to);
+    VALUE klass = CLASS_OF(recv);
+    const rb_method_entry_t *me;
     rb_thread_t *th = GET_THREAD();
     int call_status;
 
+    me = rb_method_entry(klass, idRespond_to);
     if (me && !(me->flag & NOEX_BASIC)) {
 	VALUE args[2] = {ID2SYM(mid), Qtrue};
 	if (!RTEST(vm_call0(th, recv, idRespond_to, 2, args, me))) {
@@ -279,7 +281,7 @@
     me = rb_search_method_entry(recv, mid);
     call_status = rb_method_call_status(th, me, CALL_FCALL, Qundef);
     if (call_status != NOEX_OK) {
-	if (rb_method_basic_definition_p(CLASS_OF(recv), idMethodMissing)) {
+	if (rb_method_basic_definition_p(klass, idMethodMissing)) {
 	    return Qundef;
 	}
 	else {
Index: test/ruby/test_object.rb
===================================================================
--- test/ruby/test_object.rb	(revision 32856)
+++ test/ruby/test_object.rb	(revision 32857)
@@ -181,18 +181,30 @@
     o = Object.new
     def o.to_s; 1; end
     assert_raise(TypeError) { String(o) }
+    def o.to_s; "o"; end
+    assert_equal("o", String(o))
+    def o.respond_to?(*) false; end
+    assert_raise(TypeError) { String(o) }
   end
 
   def test_check_convert_type
     o = Object.new
     def o.to_a; 1; end
     assert_raise(TypeError) { Array(o) }
+    def o.to_a; [1]; end
+    assert_equal([1], Array(o))
+    def o.respond_to?(*) false; end
+    assert_equal([o], Array(o))
   end
 
   def test_to_integer
     o = Object.new
     def o.to_i; nil; end
     assert_raise(TypeError) { Integer(o) }
+    def o.to_i; 42; end
+    assert_equal(42, Integer(o))
+    def o.respond_to?(*) false; end
+    assert_raise(TypeError) { Integer(o) }
   end
 
   class MyInteger

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

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