Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Method::Patcher should preserve method visibility

(Works around rubinius/rubinius#2248)
  • Loading branch information...
commit ad655b7384092036c043ff0ca60bb6b12db7d2aa 1 parent 1af4949
@ConradIrwin ConradIrwin authored
Showing with 9 additions and 1 deletion.
  1. +2 −1  lib/pry/method/patcher.rb
  2. +7 −0 spec/method/patcher_spec.rb
View
3  lib/pry/method/patcher.rb
@@ -97,7 +97,8 @@ def wrap(source)
def wrap_for_owner(source)
Pry.current[:pry_owner] = method.owner
owner_source = definition_for_owner(source)
- "Pry.current[:pry_owner].class_eval do; #{owner_source}\nend"
+ visibility_fix = "#{method.visibility.to_s} #{method.name.to_sym.inspect}"
+ "Pry.current[:pry_owner].class_eval do; #{owner_source}\n#{visibility_fix}\nend"
end
# Update the new source code to have the correct Module.nesting.
View
7 spec/method/patcher_spec.rb
@@ -24,4 +24,11 @@ def @x.test; :before; end
@method.redefine "def @x.test; :after; end\n"
Pry::Method(@x.method(:test)).source.strip.should == "def @x.test; :after; end"
end
+
+ it "should preserve visibility" do
+ class << @x; private :test; end
+ @method.visibility.should == :private
+ @method.redefine "def @x.test; :after; end\n"
+ Pry::Method(@x.method(:test)).visibility.should == :private
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.