[前][次][番号順一覧][スレッド一覧]

ruby-changes:64271

From: Yusuke <ko1@a...>
Date: Fri, 18 Dec 2020 16:09:32 +0900 (JST)
Subject: [ruby-changes:64271] 982443e6e3 (master): Revert "Better cooperation between public/protected/private with attr* and alias_method"

https://git.ruby-lang.org/ruby.git/commit/?id=982443e6e3

From 982443e6e373f5a3ac22ee495909cb9adffcd08d Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 18 Dec 2020 14:12:42 +0900
Subject: Revert "Better cooperation between public/protected/private with
 attr* and alias_method"

This reverts commit 81739ad4fdfcc86a769056fec352f27c686fba1b.

diff --git a/NEWS.md b/NEWS.md
index 0d794e6..1f7b02e 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -249,16 +249,6 @@ Outstanding ones only. https://github.com/ruby/ruby/blob/trunk/NEWS.md#L249
         p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]
         ```
 
-    * Module#public, Module#protected and Module#private methods now accept single
-      array argument with a list of method names. [[Feature #17314]]
-
-    * Module#attr_accessor, Module#attr_reader, Module#attr_writer and Module#attr
-      methods now return array of defined methods names as symbols.
-      [[Feature #17314]]
-
-    * Module#alias_method now returns the defined alias as symbol.
-      [[Feature #17314]]
-
 * Mutex
 
     * `Mutex` is now acquired per-`Fiber` instead of per-`Thread`. This change
diff --git a/object.c b/object.c
index 4fe6b02..552b10b 100644
--- a/object.c
+++ b/object.c
@@ -2255,42 +2255,37 @@ id_for_attr(VALUE obj, VALUE name) https://github.com/ruby/ruby/blob/trunk/object.c#L2255
 
 /*
  *  call-seq:
- *     attr_reader(symbol, ...)  -> array
- *     attr(symbol, ...)         -> array
- *     attr_reader(string, ...)  -> array
- *     attr(string, ...)         -> array
+ *     attr_reader(symbol, ...)  -> nil
+ *     attr(symbol, ...)         -> nil
+ *     attr_reader(string, ...)  -> nil
+ *     attr(string, ...)         -> nil
  *
  *  Creates instance variables and corresponding methods that return the
  *  value of each instance variable. Equivalent to calling
  *  ``<code>attr</code><i>:name</i>'' on each name in turn.
  *  String arguments are converted to symbols.
- *  Returns an array of defined methods names as symbols.
  */
 
 static VALUE
 rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass)
 {
     int i;
-    VALUE names = rb_ary_new2(argc);
 
     for (i=0; i<argc; i++) {
-	ID id = id_for_attr(klass, argv[i]);
-	rb_attr(klass, id, TRUE, FALSE, TRUE);
-	rb_ary_push(names, ID2SYM(id));
+	rb_attr(klass, id_for_attr(klass, argv[i]), TRUE, FALSE, TRUE);
     }
-    return names;
+    return Qnil;
 }
 
 /**
  *  call-seq:
- *    attr(name, ...) -> array
- *    attr(name, true) -> array
- *    attr(name, false) -> array
+ *    attr(name, ...) -> nil
+ *    attr(name, true) -> nil
+ *    attr(name, false) -> nil
  *
  *  The first form is equivalent to #attr_reader.
  *  The second form is equivalent to <code>attr_accessor(name)</code> but deprecated.
  *  The last form is equivalent to <code>attr_reader(name)</code> but deprecated.
- *  Returns an array of defined methods names as symbols.
  *--
  * \private
  * \todo can be static?
@@ -2300,57 +2295,47 @@ VALUE https://github.com/ruby/ruby/blob/trunk/object.c#L2295
 rb_mod_attr(int argc, VALUE *argv, VALUE klass)
 {
     if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) {
-	ID id = id_for_attr(klass, argv[0]);
-	VALUE names = rb_ary_new();
-
 	rb_warning("optional boolean argument is obsoleted");
-	rb_attr(klass, id, 1, RTEST(argv[1]), TRUE);
-	rb_ary_push(names, ID2SYM(id));
-	if (argv[1] == Qtrue) rb_ary_push(names, rb_str_intern(rb_sprintf("%"PRIsVALUE"=", ID2SYM(id))));
-	return names;
+	rb_attr(klass, id_for_attr(klass, argv[0]), 1, RTEST(argv[1]), TRUE);
+	return Qnil;
     }
     return rb_mod_attr_reader(argc, argv, klass);
 }
 
 /*
  *  call-seq:
- *      attr_writer(symbol, ...)    -> array
- *      attr_writer(string, ...)    -> array
+ *      attr_writer(symbol, ...)    -> nil
+ *      attr_writer(string, ...)    -> nil
  *
  *  Creates an accessor method to allow assignment to the attribute
  *  <i>symbol</i><code>.id2name</code>.
  *  String arguments are converted to symbols.
- *  Returns an array of defined methods names as symbols.
  */
 
 static VALUE
 rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass)
 {
     int i;
-    VALUE names = rb_ary_new2(argc);
 
     for (i=0; i<argc; i++) {
-	ID id = id_for_attr(klass, argv[i]);
-	rb_attr(klass, id, FALSE, TRUE, TRUE);
-	rb_ary_push(names, rb_str_intern(rb_sprintf("%"PRIsVALUE"=", ID2SYM(id))));
+	rb_attr(klass, id_for_attr(klass, argv[i]), FALSE, TRUE, TRUE);
     }
-    return names;
+    return Qnil;
 }
 
 /*
  *  call-seq:
- *     attr_accessor(symbol, ...)    -> array
- *     attr_accessor(string, ...)    -> array
+ *     attr_accessor(symbol, ...)    -> nil
+ *     attr_accessor(string, ...)    -> nil
  *
  *  Defines a named attribute for this module, where the name is
  *  <i>symbol.</i><code>id2name</code>, creating an instance variable
  *  (<code>@name</code>) and a corresponding access method to read it.
  *  Also creates a method called <code>name=</code> to set the attribute.
  *  String arguments are converted to symbols.
- *  Returns an array of defined methods names as symbols.
  *
  *     module Mod
- *       attr_accessor(:one, :two) #=> [:one, :one=, :two, :two=]
+ *       attr_accessor(:one, :two)
  *     end
  *     Mod.instance_methods.sort   #=> [:one, :one=, :two, :two=]
  */
@@ -2359,17 +2344,11 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/object.c#L2344
 rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass)
 {
     int i;
-    VALUE names = rb_ary_new2(argc * 2);
 
     for (i=0; i<argc; i++) {
-	ID id = id_for_attr(klass, argv[i]);
-	VALUE idv = ID2SYM(id);
-
-	rb_attr(klass, id, TRUE, TRUE, TRUE);
-	rb_ary_push(names, idv);
-	rb_ary_push(names, rb_str_intern(rb_sprintf("%"PRIsVALUE"=", idv)));
+	rb_attr(klass, id_for_attr(klass, argv[i]), TRUE, TRUE, TRUE);
     }
-    return names;
+    return Qnil;
 }
 
 /*
diff --git a/process.c b/process.c
index 0b2fdeb..dee565e 100644
--- a/process.c
+++ b/process.c
@@ -2075,11 +2075,12 @@ check_exec_redirect1(VALUE ary, VALUE key, VALUE param) https://github.com/ruby/ruby/blob/trunk/process.c#L2075
         rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
     }
     else {
-        int i;
+        int i, n=0;
         for (i = 0 ; i < RARRAY_LEN(key); i++) {
             VALUE v = RARRAY_AREF(key, i);
             VALUE fd = check_exec_redirect_fd(v, !NIL_P(param));
             rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
+            n++;
         }
     }
     return ary;
diff --git a/spec/ruby/core/main/fixtures/classes.rb b/spec/ruby/core/main/fixtures/classes.rb
index 757cee4..6aba948 100644
--- a/spec/ruby/core/main/fixtures/classes.rb
+++ b/spec/ruby/core/main/fixtures/classes.rb
@@ -13,14 +13,6 @@ def main_public_method https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/main/fixtures/classes.rb#L13
 end
 public :main_public_method
 
-def main_public_method2
-end
-public :main_public_method2
-
 def main_private_method
 end
 private :main_private_method
-
-def main_private_method2
-end
-private :main_private_method2
diff --git a/spec/ruby/core/main/private_spec.rb b/spec/ruby/core/main/private_spec.rb
index 78c5d28..e34e0c7 100644
--- a/spec/ruby/core/main/private_spec.rb
+++ b/spec/ruby/core/main/private_spec.rb
@@ -4,41 +4,20 @@ require_relative 'fixtures/classes' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/main/private_spec.rb#L4
 describe "main#private" do
   after :each do
     Object.send(:public, :main_public_method)
-    Object.send(:public, :main_public_method2)
   end
 
-  context "when single argument is passed and it is not an array" do
-    it "sets the visibility of the given methods to private" do
-      eval "private :main_public_method", TOPLEVEL_BINDING
-      Object.should have_private_method(:main_public_method)
-    end
-  end
-
-  context "when multiple arguments are passed" do
-    it "sets the visibility of the given methods to private" do
-      eval "private :main_public_method, :main_public_method2", TOPLEVEL_BINDING
-      Object.should have_private_method(:main_public_method)
-      Object.should have_private_method(:main_public_method2)
-    end
-  end
-
-  ruby_version_is "3.0" do
-    context "when single argument is passed and is an array" do
-      it "sets the visibility of the given methods to private" do
-        eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING
-        Object.should have_private_method(:main_public_method)
-        Object.should have_private_method(:main_public_method2)
-      end
-    end
+  it "sets the visibility of the given method to private" do
+    eval "private :main_public_method", TOPLEVEL_BINDING
+    Object.should have_private_method(:main_public_method)
   end
 
   it "returns Object" do
     eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object)
   end
 
-  it "raises a NameError when at least one of given method names is undefined" do
+  it "raises a NameError when given an undefined name" do
     -> do
-      eval "private :main_public_method, :main_undefined_method", TOPLEVEL_BINDING
+      eval "private :main_undefined_method", TOPLEVEL_BINDING
     end.should raise_error(NameError)
   end
 end
diff --git a/spec/ruby/core/main/public_spec.rb b/spec/ruby/core/main/public_spec.rb
index bfc27a9e..afe25c7 100644
--- a/spec/ruby/core/main/public_spec.rb
+++ b/spec/ruby/core/main/public_spec.rb
@@ -4,32 +4,11 @@ require_relative 'fixtures/classes' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/main/public_spec.rb#L4
 describe "main#public" do
   after :each do
     Object.send(:private, :main_private_method)
-    Object.send(:private, :main_private_method2)
   end
 
-  context "when single argument is passed and it is not an array" do
-    it "sets the visibility of the given methods to public" do
-      eval "public :main_private_method", TOPLEVEL_BINDING
-      Object.should_not have_private_method(:main_private_method)
-    end
-  end
-
-  context "when multiple arguments are passed" do
-    it "sets the visibility of the g (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]