1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Method::Patcher should preserve method visibility

(Works around https://github.com/rubinius/rubinius/issues/2248)
This commit is contained in:
Conrad Irwin 2013-03-30 17:42:46 -07:00
parent 1af49497ac
commit ad655b7384
2 changed files with 9 additions and 1 deletions

View file

@ -97,7 +97,8 @@ class Pry
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 file

@ -24,4 +24,11 @@ describe Pry::Method::Patcher do
@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