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

ruby-changes:32551

From: nobu <ko1@a...>
Date: Fri, 17 Jan 2014 20:05:10 +0900 (JST)
Subject: [ruby-changes:32551] nobu:r44630 (trunk): delegate.rb: keep special methods

nobu	2014-01-17 20:05:03 +0900 (Fri, 17 Jan 2014)

  New Revision: 44630

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

  Log:
    delegate.rb: keep special methods
    
    * lib/delegate.rb (Delegator): keep source information methods
      which start and end with '__'.  [ruby-core:58572] [Bug #9155]

  Modified files:
    trunk/ChangeLog
    trunk/lib/delegate.rb
    trunk/test/test_delegate.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44629)
+++ ChangeLog	(revision 44630)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jan 17 20:05:02 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/delegate.rb (Delegator): keep source information methods
+	  which start and end with '__'.  [ruby-core:58572] [Bug #9155]
+
 Fri Jan 17 17:58:04 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* eval.c (rb_mod_s_constants): return its own constants for other
Index: lib/delegate.rb
===================================================================
--- lib/delegate.rb	(revision 44629)
+++ lib/delegate.rb	(revision 44630)
@@ -48,7 +48,7 @@ class Delegator < BasicObject https://github.com/ruby/ruby/blob/trunk/lib/delegate.rb#L48
       undef_method m
     end
     private_instance_methods.each do |m|
-      if /\Ablock_given\?\z|iterator\?\z|\A__raise__\z/ =~ m
+      if /\Ablock_given\?\z|iterator\?\z|\A__.*__\z/ =~ m
         next
       end
       undef_method m
Index: test/test_delegate.rb
===================================================================
--- test/test_delegate.rb	(revision 44629)
+++ test/test_delegate.rb	(revision 44630)
@@ -180,4 +180,61 @@ class TestDelegateClass < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_delegate.rb#L180
     x = assert_nothing_raised(ArgumentError, bug9155) {break Bug9155.new(1)}
     assert_equal(1, x.to_i, bug9155)
   end
+
+  class Bug9403
+    Name = '[ruby-core:59718] [Bug #9403]'
+    SD = SimpleDelegator.new(new)
+    class << SD
+      def method_name
+        __method__
+      end
+      def callee_name
+        __callee__
+      end
+      alias aliased_name callee_name
+      def dir_name
+        __dir__
+      end
+    end
+    dc = DelegateClass(self)
+    dc.class_eval do
+      def method_name
+        __method__
+      end
+      def callee_name
+        __callee__
+      end
+      alias aliased_name callee_name
+      def dir_name
+        __dir__
+      end
+    end
+    DC = dc.new(new)
+  end
+
+  def test_method_in_simple_delegator
+    assert_equal(:method_name, Bug9403::SD.method_name, Bug9403::Name)
+  end
+
+  def test_callee_in_simple_delegator
+    assert_equal(:callee_name, Bug9403::SD.callee_name, Bug9403::Name)
+    assert_equal(:aliased_name, Bug9403::SD.aliased_name, Bug9403::Name)
+  end
+
+  def test_dir_in_simple_delegator
+    assert_equal(__dir__, Bug9403::SD.dir_name, Bug9403::Name)
+  end
+
+  def test_method_in_delegator_class
+    assert_equal(:method_name, Bug9403::DC.method_name, Bug9403::Name)
+  end
+
+  def test_callee_in_delegator_class
+    assert_equal(:callee_name, Bug9403::DC.callee_name, Bug9403::Name)
+    assert_equal(:aliased_name, Bug9403::DC.aliased_name, Bug9403::Name)
+  end
+
+  def test_dir_in_delegator_class
+    assert_equal(__dir__, Bug9403::DC.dir_name, Bug9403::Name)
+  end
 end

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

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