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

ruby-changes:70386

From: Jeremy <ko1@a...>
Date: Tue, 21 Dec 2021 04:02:32 +0900 (JST)
Subject: [ruby-changes:70386] 3bd5f27f73 (master): Remove Class#descendants

https://git.ruby-lang.org/ruby.git/commit/?id=3bd5f27f73

From 3bd5f27f737c7d365b7d01c43d77a958c224ab16 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Mon, 20 Dec 2021 08:26:14 -0800
Subject: Remove Class#descendants

---
 NEWS.md                                  | 15 -------------
 class.c                                  | 25 ---------------------
 object.c                                 |  1 -
 spec/ruby/core/class/descendants_spec.rb | 38 --------------------------------
 test/ruby/test_class.rb                  | 32 ---------------------------
 5 files changed, 111 deletions(-)
 delete mode 100644 spec/ruby/core/class/descendants_spec.rb

diff --git a/NEWS.md b/NEWS.md
index ce737b24fe6..52ef16f015e 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -126,20 +126,6 @@ Note: We're only listing outstanding class updates. https://github.com/ruby/ruby/blob/trunk/NEWS.md#L126
 
 * Class
 
-    *   Class#descendants, which returns an array of classes
-        directly or indirectly inheriting from the receiver, not
-        including the receiver or singleton classes.
-        [[Feature #14394]]
-
-        ```ruby
-        class A; end
-        class B < A; end
-        class C < B; end
-        A.descendants    #=> [B, C]
-        B.descendants    #=> [C]
-        C.descendants    #=> []
-        ```
-
     *   Class#subclasses, which returns an array of classes
         directly inheriting from the receiver, not
         including singleton classes.
@@ -555,7 +541,6 @@ See [the repository](https://github.com/ruby/error_highlight) in detail. https://github.com/ruby/ruby/blob/trunk/NEWS.md#L541
 [Feature #12495]: https://bugs.ruby-lang.org/issues/12495
 [Feature #12913]: https://bugs.ruby-lang.org/issues/12913
 [Feature #14256]: https://bugs.ruby-lang.org/issues/14256
-[Feature #14394]: https://bugs.ruby-lang.org/issues/14394
 [Feature #14579]: https://bugs.ruby-lang.org/issues/14579
 [Feature #15198]: https://bugs.ruby-lang.org/issues/15198
 [Feature #15211]: https://bugs.ruby-lang.org/issues/15211
diff --git a/class.c b/class.c
index f1e8953f81f..dd9da9b66fb 100644
--- a/class.c
+++ b/class.c
@@ -1427,31 +1427,6 @@ class_descendants(VALUE klass, bool immediate_only) https://github.com/ruby/ruby/blob/trunk/class.c#L1427
     return data.buffer;
 }
 
-/*
- *  call-seq:
- *     descendants -> array
- *
- *  Returns an array of classes where the receiver is one of
- *  the ancestors of the class, excluding the receiver and
- *  singleton classes. The order of the returned array is not
- *  defined.
- *
- *     class A; end
- *     class B < A; end
- *     class C < B; end
- *
- *     A.descendants        #=> [B, C]
- *     B.descendants        #=> [C]
- *     C.descendants        #=> []
- */
-
-VALUE
-rb_class_descendants(VALUE klass)
-{
-    return class_descendants(klass, false);
-}
-
-
 /*
  *  call-seq:
  *     subclasses -> array
diff --git a/object.c b/object.c
index 6e739014a1e..430f7eafd05 100644
--- a/object.c
+++ b/object.c
@@ -4660,7 +4660,6 @@ InitVM_Object(void) https://github.com/ruby/ruby/blob/trunk/object.c#L4660
     rb_define_method(rb_cClass, "new", rb_class_new_instance_pass_kw, -1);
     rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
     rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
-    rb_define_method(rb_cClass, "descendants", rb_class_descendants, 0); /* in class.c */
     rb_define_method(rb_cClass, "subclasses", rb_class_subclasses, 0); /* in class.c */
     rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
     rb_undef_method(rb_cClass, "extend_object");
diff --git a/spec/ruby/core/class/descendants_spec.rb b/spec/ruby/core/class/descendants_spec.rb
deleted file mode 100644
index f87cd68be82..00000000000
--- a/spec/ruby/core/class/descendants_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/object.c#L0
-require_relative '../../spec_helper'
-require_relative '../module/fixtures/classes'
-
-ruby_version_is '3.1' do
-  describe "Class#descendants" do
-    it "returns a list of classes descended from self (excluding self)" do
-      assert_descendants(ModuleSpecs::Parent, [ModuleSpecs::Child, ModuleSpecs::Child2, ModuleSpecs::Grandchild])
-    end
-
-    it "does not return included modules" do
-      parent = Class.new
-      child = Class.new(parent)
-      mod = Module.new
-      parent.include(mod)
-
-      assert_descendants(parent, [child])
-    end
-
-    it "does not return singleton classes" do
-      a = Class.new
-
-      a_obj = a.new
-      def a_obj.force_singleton_class
-        42
-      end
-
-      a.descendants.should_not include(a_obj.singleton_class)
-    end
-
-    it "has 1 entry per module or class" do
-      ModuleSpecs::Parent.descendants.should == ModuleSpecs::Parent.descendants.uniq
-    end
-
-    def assert_descendants(mod, descendants)
-      mod.descendants.sort_by(&:inspect).should == descendants.sort_by(&:inspect)
-    end
-  end
-end
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index 28285705bf3..07c34ce9d57 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -738,38 +738,6 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_class.rb#L738
     assert_same(c, Module.new.const_set(:Foo, c))
   end
 
-  def test_descendants
-    c = Class.new
-    sc = Class.new(c)
-    ssc = Class.new(sc)
-    [c, sc, ssc].each do |k|
-      k.include Module.new
-      k.new.define_singleton_method(:force_singleton_class){}
-    end
-    assert_equal([sc, ssc], c.descendants)
-    assert_equal([ssc], sc.descendants)
-    assert_equal([], ssc.descendants)
-
-    object_descendants = Object.descendants
-    assert_include(object_descendants, c)
-    assert_include(object_descendants, sc)
-    assert_include(object_descendants, ssc)
-  end
-
-  def test_descendants_gc
-    c = Class.new
-    100000.times { Class.new(c) }
-    assert(c.descendants.size <= 100000)
-  end
-
-  def test_descendants_gc_stress
-    10000.times do
-      c = Class.new
-      100.times { Class.new(c) }
-      assert(c.descendants.size <= 100)
-    end
-  end
-
   def test_subclasses
     c = Class.new
     sc = Class.new(c)
-- 
cgit v1.2.1


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

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