summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-09-16 21:29:36 +0900
committerHomu <homu@barosl.com>2016-09-16 21:29:36 +0900
commit0ed87c48e000be522024f5e91c18376dfe955376 (patch)
treeff8135206a61956e5893ce5bf0a780e2101e683d
parent4d885bca65f9b1324a68e3f5c0c56575076a204c (diff)
parent6418a10fe4e26dd0904def5c05065390339db11a (diff)
downloadbundler-homu-tmp.tar.gz
Auto merge of #4983 - bundler:seg-redefine-method-visibility, r=indirecthomu-tmp
[RubygemsIntegration] Ensure redefined methods have the same visibility Closes #4975 \c @indirect @headius I'd love to get this out as 1.13.2 asap, if it works
-rw-r--r--lib/bundler/rubygems_integration.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index c1bb6c7ab8..23ae95aa04 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -489,6 +489,7 @@ module Bundler
end
def redefine_method(klass, method, unbound_method = nil, &block)
+ visibility = method_visibility(klass, method)
begin
if (instance_method = klass.instance_method(method)) && method != :initialize
# doing this to ensure we also get private methods
@@ -501,8 +502,20 @@ module Bundler
@replaced_methods[[method, klass]] = instance_method
if unbound_method
klass.send(:define_method, method, unbound_method)
+ klass.send(visibility, method)
elsif block
klass.send(:define_method, method, &block)
+ klass.send(visibility, method)
+ end
+ end
+
+ def method_visibility(klass, method)
+ if klass.private_method_defined?(method)
+ :private
+ elsif klass.protected_method_defined?(method)
+ :protected
+ else
+ :public
end
end