diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-09-14 19:16:15 +0200 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-09-14 19:16:15 +0200 |
commit | 2fc48008f072055c05e4d46ee4250ae7c74d7548 (patch) | |
tree | 895aac7a20ca21c390a06bad3f936d0cc6c58a30 | |
parent | ee36873804e3c3bdd9d5297e762a3ac9e775cc57 (diff) | |
download | bundler-seg-redefine-method-visibility.tar.gz |
[RubygemsIntegration] Ensure redefined methods have the same visibilityseg-redefine-method-visibility
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index c1bb6c7ab8..23648554b7 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 @@ -504,6 +505,17 @@ module Bundler elsif block klass.send(:define_method, method, &block) end + klass.send(visibility, method) + end + + def method_visibility(klass, method) + if klass.private_method_defined?(method) + :private + elsif klass.protected_method_defined?(method) + :protected + else + :public + end end # Rubygems 1.4 through 1.6 |