summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-09-16 21:29:36 +0900
committerSamuel Giddins <segiddins@segiddins.me>2016-09-30 12:27:07 -0500
commitc45389622ed9a893a5851c251d5a5e97e6d499bc (patch)
tree0e5f4b3b325ece32eb3dbc9db9213c40f4eafb51
parentaeb283f95f99a429b8b04cba997615b0140320fc (diff)
downloadbundler-c45389622ed9a893a5851c251d5a5e97e6d499bc.tar.gz
Auto merge of #4983 - bundler:seg-redefine-method-visibility, r=indirect
[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 43b7091e74..1c44ef3ddd 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -500,6 +500,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
@@ -512,8 +513,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