diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-15 08:07:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-15 08:07:39 +0000 |
commit | ca5739979dc932e809cb70d243ecc07d380d2725 (patch) | |
tree | 69296750e2afc4d25a0466cb3f51ac1668334923 | |
parent | 3eac78dd88982c2f1388d7a974c58ed5d2214e12 (diff) | |
download | ruby-ca5739979dc932e809cb70d243ecc07d380d2725.tar.gz |
delegate.rb: get rid of global function interference
* lib/delegate.rb (Delegator#send): override to get rid of global function interference.
[Fixes GH-449]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/delegate.rb | 1 | ||||
-rw-r--r-- | test/test_delegate.rb | 12 |
3 files changed, 18 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Fri Nov 15 17:07:31 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@ruby-lang.org> * ext/objspace/objspace_dump.c (dump_output): allow IO object as diff --git a/lib/delegate.rb b/lib/delegate.rb index a2ca46fafa..74b13aa8a3 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -74,6 +74,7 @@ class Delegator < BasicObject $@.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 diff --git a/test/test_delegate.rb b/test/test_delegate.rb index a09451b88f..d816a62bf5 100644 --- a/test/test_delegate.rb +++ b/test/test_delegate.rb @@ -133,4 +133,16 @@ class TestDelegateClass < Test::Unit::TestCase 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 |