mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix setting method visibility on method wrapped with prepend
Ignore prepended modules when looking for already defined methods on a class to set the visibility on. [Fix GH-1834] From: Dylan Thacker-Smith <Dylan.Smith@shopify.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f2b094a522
commit
ae36cf62b7
3 changed files with 61 additions and 2 deletions
|
|
@ -51,4 +51,43 @@ describe "Module#private" do
|
|||
Module.new.send(:private, :undefined)
|
||||
end.should raise_error(NameError)
|
||||
end
|
||||
|
||||
it "only makes the method private in the class it is called on" do
|
||||
base = Class.new do
|
||||
def wrapped
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
klass = Class.new(base) do
|
||||
def wrapped
|
||||
super + 1
|
||||
end
|
||||
private :wrapped
|
||||
end
|
||||
|
||||
base.new.wrapped.should == 1
|
||||
lambda do
|
||||
klass.new.wrapped
|
||||
end.should raise_error(NameError)
|
||||
end
|
||||
|
||||
it "continues to allow a prepended module method to call super" do
|
||||
wrapper = Module.new do
|
||||
def wrapped
|
||||
super + 1
|
||||
end
|
||||
end
|
||||
|
||||
klass = Class.new do
|
||||
prepend wrapper
|
||||
|
||||
def wrapped
|
||||
1
|
||||
end
|
||||
private :wrapped
|
||||
end
|
||||
|
||||
klass.new.wrapped.should == 2
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue