summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-20 09:52:52 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-20 09:52:52 +0000
commitf4aea9108d19b304e8a7f9d2ec4763eadf4a64ba (patch)
treed4e36f6ac9b50372a7651575543f2cd091fa7aea /spec
parent42fdd9407d420f80c7c664ae22615986959b9c5b (diff)
merge revision(s) 62725: [Backport #14604]
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/branches/ruby_2_5@62860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/module/private_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/ruby/core/module/private_spec.rb b/spec/ruby/core/module/private_spec.rb
index bfdb5016c2..07b8f4c781 100644
--- a/spec/ruby/core/module/private_spec.rb
+++ b/spec/ruby/core/module/private_spec.rb
@@ -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