зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
26b8c0890f
Коммит
a6569ad637
|
@ -1,3 +1,9 @@
|
||||||
|
Sat Feb 6 12:02:36 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/delegate.rb (Delegator#method_missing),
|
||||||
|
(Delegator.delegating_block): don't hide backtrace from
|
||||||
|
__getobj__ and reduced exception messages when $DEBUG.
|
||||||
|
|
||||||
Sat Feb 6 11:35:08 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Feb 6 11:35:08 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/socket/ipsocket.c (ip_addr, ip_peeraddr),
|
* ext/socket/ipsocket.c (ip_addr, ip_peeraddr),
|
||||||
|
|
|
@ -139,18 +139,11 @@ class Delegator < BasicObject
|
||||||
|
|
||||||
# Handles the magic of delegation through \_\_getobj\_\_.
|
# Handles the magic of delegation through \_\_getobj\_\_.
|
||||||
def method_missing(m, *args, &block)
|
def method_missing(m, *args, &block)
|
||||||
|
target = self.__getobj__
|
||||||
begin
|
begin
|
||||||
target = self.__getobj__
|
target.respond_to?(m) ? target.__send__(m, *args, &block) : super(m, *args, &block)
|
||||||
unless target.respond_to?(m)
|
ensure
|
||||||
super(m, *args, &block)
|
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -267,12 +260,11 @@ end
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
def Delegator.delegating_block(mid)
|
def Delegator.delegating_block(mid)
|
||||||
lambda do |*args, &block|
|
lambda do |*args, &block|
|
||||||
|
target = self.__getobj__
|
||||||
begin
|
begin
|
||||||
__getobj__.__send__(mid, *args, &block)
|
target.__send__(mid, *args, &block)
|
||||||
rescue
|
ensure
|
||||||
re = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o
|
$@.delete_if {|t| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o =~ t} if $@
|
||||||
$!.backtrace.delete_if {|t| re =~ t}
|
|
||||||
raise
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче