summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-21 07:33:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-21 07:33:01 +0000
commit594eec5b7d2ca6ae1c8473b570af312dd49c40b5 (patch)
tree01184eaaddd1079fc0d9672c325c91ef087c5384
parentd3edb4a85e08bbcd208f0a201f187d9ddd0a918d (diff)
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
-rw-r--r--ChangeLog15
-rw-r--r--lib/delegate.rb26
2 files changed, 17 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index deb405c9b1..b484ca5d60 100644
--- a/ChangeLog
+++ b/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
diff --git a/lib/delegate.rb b/lib/delegate.rb
index b929895d1f..442a3762f2 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -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)
- 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)
+ 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 $@
+ $@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:(?:#{[__LINE__-7, __LINE__-5, __LINE__-3].join('|')}):"o =~ t} if $@
end
end