aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-19 16:27:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-19 16:27:40 +0000
commita9a6c103e536bf63c24fc2c207ee63072c73a450 (patch)
treeb93818467ffe44b2860059ba60cbf93d8fc4d2ad
parentb9294f226b87808c1c1b2b33d3fc27a11a1a7a21 (diff)
downloadruby-a9a6c103e536bf63c24fc2c207ee63072c73a450.tar.gz
delegate.rb: refix r43682
* lib/delegate.rb (Delegator#send): separate from method_missing so that super calls proper method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/delegate.rb13
-rw-r--r--test/test_delegate.rb9
3 files changed, 26 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f8fdd18f18..38385a1b60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Nov 20 01:27:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/delegate.rb (Delegator#send): separate from method_missing so
+ that super calls proper method.
+
Tue Nov 19 23:38:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (--with-os-version-style): option to transform target
diff --git a/lib/delegate.rb b/lib/delegate.rb
index 74b13aa8a3..b929895d1f 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -74,7 +74,18 @@ class Delegator < BasicObject
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
end
end
- alias send method_missing
+
+ #
+ # Handles the magic of delegation through \_\_getobj\_\_.
+ #
+ def send(m, *args, &block)
+ target = self.__getobj__
+ begin
+ target.respond_to?(m) ? target.__send__(m, *args, &block) : super(m, *args, &block)
+ ensure
+ $@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
+ end
+ end
#
# 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 d816a62bf5..6448ef90dd 100644
--- a/test/test_delegate.rb
+++ b/test/test_delegate.rb
@@ -145,4 +145,13 @@ class TestDelegateClass < Test::Unit::TestCase
assert_nothing_raised(ArgumentError) {d.open}
assert_nothing_raised(ArgumentError) {d.send(:open)}
end
+
+ def test_send_method_in_delegator
+ d = Class.new(SimpleDelegator) do
+ def foo
+ "foo"
+ end
+ end.new(Object.new)
+ assert_equal("foo", d.send(:foo))
+ end
end