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

ruby-changes:31603

From: nobu <ko1@a...>
Date: Fri, 15 Nov 2013 17:07:45 +0900 (JST)
Subject: [ruby-changes:31603] nobu:r43682 (trunk): delegate.rb: get rid of global function interference

nobu	2013-11-15 17:07:39 +0900 (Fri, 15 Nov 2013)

  New Revision: 43682

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

  Log:
    delegate.rb: get rid of global function interference
    
    * lib/delegate.rb (Delegator#send): override to get rid of global function interference.
      [Fixes GH-449]

  Modified files:
    trunk/ChangeLog
    trunk/lib/delegate.rb
    trunk/test/test_delegate.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43681)
+++ ChangeLog	(revision 43682)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Nov 15 17:07:31 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/delegate.rb (Delegator#send): override to get rid of global function interference.
+	  [Fixes GH-449]
+
 Fri Nov 15 01:06:04 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/objspace/objspace_dump.c (dump_output): allow IO object as
Index: lib/delegate.rb
===================================================================
--- lib/delegate.rb	(revision 43681)
+++ lib/delegate.rb	(revision 43682)
@@ -74,6 +74,7 @@ class Delegator < BasicObject https://github.com/ruby/ruby/blob/trunk/lib/delegate.rb#L74
       $@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
     end
   end
+  alias send method_missing
 
   #
   # Checks for a method provided by this the delegate object by forwarding the
Index: test/test_delegate.rb
===================================================================
--- test/test_delegate.rb	(revision 43681)
+++ test/test_delegate.rb	(revision 43682)
@@ -133,4 +133,16 @@ class TestDelegateClass < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_delegate.rb#L133
     assert_raise(NoMethodError, '[ruby-dev:40314]#4') {d.delegate_test_private}
     assert_raise(NoMethodError, '[ruby-dev:40314]#5') {d.send(:delegate_test_private)}
   end
+
+  def test_global_function
+    klass = Class.new do
+      def open
+      end
+    end
+    obj = klass.new
+    d = SimpleDelegator.new(obj)
+    assert_nothing_raised(ArgumentError) {obj.open}
+    assert_nothing_raised(ArgumentError) {d.open}
+    assert_nothing_raised(ArgumentError) {d.send(:open)}
+  end
 end

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

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