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
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>
|
Thu Nov 21 16:25:08 2013 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* test/uri/test_generic.rb (URI#test_merge): Test uri + URI(path)
|
* 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
|
* lib/rdoc/constant.rb (RDoc::Constant#documented?): workaround for
|
||||||
NoMethodError when the original of alias is not found.
|
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>
|
Tue Nov 19 23:38:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in (--with-os-version-style): option to transform target
|
* 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.
|
* 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>
|
Fri Nov 15 01:06:04 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/objspace/objspace_dump.c (dump_output): allow IO object as
|
* 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|
|
[:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash].each do |m|
|
||||||
undef_method m
|
undef_method m
|
||||||
end
|
end
|
||||||
|
private_instance_methods.each do |m|
|
||||||
|
next if /\Ablock_given\?\z|iterator\?\z/ =~ m
|
||||||
|
undef_method m
|
||||||
|
end
|
||||||
end
|
end
|
||||||
include kernel
|
include kernel
|
||||||
|
|
||||||
@ -69,21 +73,15 @@ class Delegator < BasicObject
|
|||||||
def method_missing(m, *args, &block)
|
def method_missing(m, *args, &block)
|
||||||
target = self.__getobj__
|
target = self.__getobj__
|
||||||
begin
|
begin
|
||||||
target.respond_to?(m) ? target.__send__(m, *args, &block) : super(m, *args, &block)
|
if target.respond_to?(m)
|
||||||
ensure
|
target.__send__(m, *args, &block)
|
||||||
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@
|
elsif ::Kernel.respond_to?(m, true)
|
||||||
|
::Kernel.instance_method(m).bind(self).(*args, &block)
|
||||||
|
else
|
||||||
|
super(m, *args, &block)
|
||||||
end
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user