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

ruby-changes:37083

From: headius <ko1@a...>
Date: Wed, 7 Jan 2015 05:57:04 +0900 (JST)
Subject: [ruby-changes:37083] headius:r49164 (trunk): * test/ruby/test_method.rb: Add test for &-coersion of an

headius	2015-01-07 05:56:49 +0900 (Wed, 07 Jan 2015)

  New Revision: 49164

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

  Log:
    * test/ruby/test_method.rb: Add test for &-coersion of an
      UnboundMethod.
    * test/ruby/test_module.rb: Add test for define_method given an
      UnboundMethod.

  Modified files:
    trunk/test/ruby/test_method.rb
    trunk/test/ruby/test_module.rb
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 49163)
+++ test/ruby/test_module.rb	(revision 49164)
@@ -2011,6 +2011,25 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L2011
     RUBY
   end
 
+  def test_define_method_with_unbound_method
+    # Passing an UnboundMethod to define_method succeeds if it is from an ancestor
+    assert_nothing_raised do
+      cls = Class.new(String) do
+        define_method('foo', String.instance_method(:to_s))
+      end
+
+      obj = cls.new('bar')
+      assert_equal('bar', obj.foo)
+    end
+
+    # Passing an UnboundMethod to define_method fails if it is not from an ancestor
+    assert_raise(TypeError) do
+      Class.new do
+        define_method('foo', String.instance_method(:to_s))
+      end
+    end
+  end
+
   private
 
   def assert_top_method_is_private(method)
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 49163)
+++ test/ruby/test_method.rb	(revision 49164)
@@ -652,6 +652,15 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L652
       EOC
   end
 
+  def test_unbound_method_proc_coerce
+    # '&' coercion of an UnboundMethod raises TypeError
+    assert_raise(TypeError) do
+      Class.new do
+        define_method('foo', &Object.instance_method(:to_s))
+      end
+    end
+  end
+
   def test___dir__
     assert_instance_of String, __dir__
     assert_equal(File.dirname(File.realpath(__FILE__)), __dir__)

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

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