Index: spec/ruby/core/main/private_spec.rb =================================================================== --- spec/ruby/core/main/private_spec.rb (revision 62008) +++ spec/ruby/core/main/private_spec.rb (working copy) @@ -11,10 +11,20 @@ Object.should have_private_method(:main_public_method) end - it "returns Object" do - eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object) + ruby_version_is ""..."2.6" do + it "returns Object" do + eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object) + end end + ruby_version_is "2.6" do + it "returns the argument(s) or Object" do + eval("private :main_public_method", TOPLEVEL_BINDING).should equal(:main_public_method) + eval("private :main_public_method, :main_private_method", TOPLEVEL_BINDING).should eql([:main_public_method, :main_private_method]) + eval("private", TOPLEVEL_BINDING).should equal(Object) + end + end + it "raises a NameError when given an undefined name" do lambda do eval "private :main_undefined_method", TOPLEVEL_BINDING Index: spec/ruby/core/main/public_spec.rb =================================================================== --- spec/ruby/core/main/public_spec.rb (revision 62008) +++ spec/ruby/core/main/public_spec.rb (working copy) @@ -11,10 +11,20 @@ Object.should_not have_private_method(:main_private_method) end - it "returns Object" do - eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object) + ruby_version_is ""..."2.6" do + it "returns Object" do + eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object) + end end + ruby_version_is "2.6" do + it "returns the argument(s) or Object" do + eval("public :main_private_method", TOPLEVEL_BINDING).should equal(:main_private_method) + eval("public :main_private_method, :main_public_method", TOPLEVEL_BINDING).should eql([:main_private_method, :main_public_method]) + eval("public", TOPLEVEL_BINDING).should equal(Object) + end + end + it "raises a NameError when given an undefined name" do lambda do eval "public :main_undefined_method", TOPLEVEL_BINDING Index: spec/ruby/core/module/private_spec.rb =================================================================== --- spec/ruby/core/module/private_spec.rb (revision 62008) +++ spec/ruby/core/module/private_spec.rb (working copy) @@ -38,14 +38,28 @@ :module_specs_public_method_on_object_for_kernel_private) end - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - private(:foo).should equal(self) - private.should equal(self) + ruby_version_is ""..."2.6" do + it "returns self" do + (class << Object.new; self; end).class_eval do + def foo; end + private(:foo).should equal(self) + private.should equal(self) + end end end + ruby_version_is "2.6" do + it "returns the argument(s) or self" do + (class << Object.new; self; end).class_eval do + def foo; end + def bar; end + private(:foo).should equal(:foo) + private(:foo, :bar).should eql([:foo, :bar]) + private.should equal(self) + end + end + end + it "raises a NameError when given an undefined name" do lambda do Module.new.send(:private, :undefined) Index: spec/ruby/core/module/protected_spec.rb =================================================================== --- spec/ruby/core/module/protected_spec.rb (revision 62008) +++ spec/ruby/core/module/protected_spec.rb (working copy) @@ -39,14 +39,28 @@ :module_specs_public_method_on_object_for_kernel_protected) end - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - protected(:foo).should equal(self) - protected.should equal(self) + ruby_version_is ""..."2.6" do + it "returns self" do + (class << Object.new; self; end).class_eval do + def foo; end + protected(:foo).should equal(self) + protected.should equal(self) + end end end + ruby_version_is "2.6" do + it "returns the argument(s) or self" do + (class << Object.new; self; end).class_eval do + def foo; end + def bar; end + protected(:foo).should equal(:foo) + protected(:foo, :bar).should eql([:foo, :bar]) + protected.should equal(self) + end + end + end + it "raises a NameError when given an undefined name" do lambda do Module.new.send(:protected, :undefined) Index: spec/ruby/core/module/public_spec.rb =================================================================== --- spec/ruby/core/module/public_spec.rb (revision 62008) +++ spec/ruby/core/module/public_spec.rb (working copy) @@ -27,15 +27,30 @@ :module_specs_private_method_on_object_for_kernel_public) end - it "returns self" do - (class << Object.new; self; end).class_eval do - def foo; end - private :foo - public(:foo).should equal(self) - public.should equal(self) + ruby_version_is ""..."2.6" do + it "returns self" do + (class << Object.new; self; end).class_eval do + def foo; end + private :foo + public(:foo).should equal(self) + public.should equal(self) + end end end + ruby_version_is "2.6" do + it "returns the arugment(s) or self" do + (class << Object.new; self; end).class_eval do + def foo; end + def bar; end + private :foo, :bar + public(:foo).should equal(:foo) + public(:foo, :bar).should eql([:foo, :bar]) + public.should equal(self) + end + end + end + it "raises a NameError when given an undefined name" do lambda do Module.new.send(:public, :undefined) Index: vm_method.c =================================================================== --- vm_method.c (revision 62008) +++ vm_method.c (working copy) @@ -1652,18 +1652,24 @@ { if (argc == 0) { rb_scope_visibility_set(visi); + return module; } else { set_method_visibility(module, argc, argv, visi); + if (argc == 1) { + return *argv; + } + else { + return rb_ary_new_from_values(argc, argv); + } } - return module; } /* * call-seq: * public -> self - * public(symbol, ...) -> self - * public(string, ...) -> self + * public(symbol, ...) -> aSymbol or [symbol, ...] + * public(string, ...) -> sString or [string, ...] * * With no arguments, sets the default visibility for subsequently * defined methods to public. With arguments, sets the named methods to @@ -1680,8 +1686,8 @@ /* * call-seq: * protected -> self - * protected(symbol, ...) -> self - * protected(string, ...) -> self + * protected(symbol, ...) -> aSymbol or [symbol, ...] + * protected(string, ...) -> aString or [string, ...] * * With no arguments, sets the default visibility for subsequently * defined methods to protected. With arguments, sets the named methods @@ -1707,8 +1713,8 @@ /* * call-seq: * private -> self - * private(symbol, ...) -> self - * private(string, ...) -> self + * private(symbol, ...) -> aSymbol or [symbol, ...] + * private(string, ...) -> aString or [string, ...] * * With no arguments, sets the default visibility for subsequently * defined methods to private. With arguments, sets the named methods