mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
delegate.rb: try private methods after the target
* lib/delegate.rb (Delegator#method_missing): try private methods defined in Kernel after the target. [Fixes GH-449] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d3edb4a85e
commit
594eec5b7d
2 changed files with 17 additions and 24 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,8 @@
|
|||
Thu Nov 21 16:32:47 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/delegate.rb (Delegator#method_missing): try private methods defined in
|
||||
Kernel after the target. [Fixes GH-449]
|
||||
|
||||
Thu Nov 21 16:25:08 2013 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* test/uri/test_generic.rb (URI#test_merge): Test uri + URI(path)
|
||||
|
@ -120,11 +125,6 @@ Wed Nov 20 01:39:02 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
|||
* lib/rdoc/constant.rb (RDoc::Constant#documented?): workaround for
|
||||
NoMethodError when the original of alias is not found.
|
||||
|
||||
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
|
||||
|
@ -287,11 +287,6 @@ Sat Nov 16 00:18:36 2013 Masaki Matsushita <glass.saga@gmail.com>
|
|||
|
||||
* test/ruby/test_beginendblock.rb: test for above.
|
||||
|
||||
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
|
||||
|
|
|
@ -46,6 +46,10 @@ class Delegator < BasicObject
|
|||
[:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash].each do |m|
|
||||
undef_method m
|
||||
end
|
||||
private_instance_methods.each do |m|
|
||||
next if /\Ablock_given\?\z|iterator\?\z/ =~ m
|
||||
undef_method m
|
||||
end
|
||||
end
|
||||
include kernel
|
||||
|
||||
|
@ -69,21 +73,15 @@ class Delegator < BasicObject
|
|||
def method_missing(m, *args, &block)
|
||||
target = self.__getobj__
|
||||
begin
|
||||
target.respond_to?(m) ? target.__send__(m, *args, &block) : super(m, *args, &block)
|
||||
if target.respond_to?(m)
|
||||
target.__send__(m, *args, &block)
|
||||
elsif ::Kernel.respond_to?(m, true)
|
||||
::Kernel.instance_method(m).bind(self).(*args, &block)
|
||||
else
|
||||
super(m, *args, &block)
|
||||
end
|
||||
ensure
|
||||
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# 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 $@
|
||||
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:(?:#{[__LINE__-7, __LINE__-5, __LINE__-3].join('|')}):"o =~ t} if $@
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue