aboutsummaryrefslogtreecommitdiffstats
path: root/lib/delegate.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-06 03:02:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-06 03:02:40 +0000
commita6569ad637e46eeb93bd28fe1ffe3c173dc43903 (patch)
treeef22087261445945a2cf696d7b50b3ae8621a5c8 /lib/delegate.rb
parent26b8c0890f4177f004b40adaad1a412e3f22cb72 (diff)
downloadruby-a6569ad637e46eeb93bd28fe1ffe3c173dc43903.tar.gz
* lib/delegate.rb (Delegator#method_missing),
(Delegator.delegating_block): don't hide backtrace from __getobj__ and reduced exception messages when $DEBUG. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/delegate.rb')
-rw-r--r--lib/delegate.rb24
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index 0d5dc23b6e..2891167fa8 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -139,18 +139,11 @@ class Delegator < BasicObject
# Handles the magic of delegation through \_\_getobj\_\_.
def method_missing(m, *args, &block)
+ target = self.__getobj__
begin
- target = self.__getobj__
- unless target.respond_to?(m)
- super(m, *args, &block)
- else
- target.__send__(m, *args, &block)
- end
- rescue ::Exception
- if i = $@.index{|s| %r"\A#{Regexp.quote(__FILE__)}:\d+:in `method_missing'\z"o =~ s}
- $@[0..i] = []
- end
- ::Kernel::raise
+ 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
@@ -267,12 +260,11 @@ end
# :stopdoc:
def Delegator.delegating_block(mid)
lambda do |*args, &block|
+ target = self.__getobj__
begin
- __getobj__.__send__(mid, *args, &block)
- rescue
- re = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o
- $!.backtrace.delete_if {|t| re =~ t}
- raise
+ target.__send__(mid, *args, &block)
+ ensure
+ $@.delete_if {|t| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o =~ t} if $@
end
end
end