summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-12-20 08:26:14 -0800
committerJeremy Evans <code@jeremyevans.net>2021-12-20 11:02:15 -0800
commit3bd5f27f737c7d365b7d01c43d77a958c224ab16 (patch)
tree2e3933d29fc01a17999c3664969017df77a998a0
parentc57ac4c6e0acf9b4c1fbb3092eefc89873c5d249 (diff)
Remove Class#descendants
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5309
-rw-r--r--NEWS.md15
-rw-r--r--class.c25
-rw-r--r--object.c1
-rw-r--r--spec/ruby/core/class/descendants_spec.rb38
-rw-r--r--test/ruby/test_class.rb32
5 files changed, 0 insertions, 111 deletions
diff --git a/NEWS.md b/NEWS.md
index ce737b24fe..52ef16f015 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -126,20 +126,6 @@ Note: We're only listing outstanding class updates.
* 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.
[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 f1e8953f81..dd9da9b66f 100644
--- a/class.c
+++ b/class.c
@@ -1429,31 +1429,6 @@ class_descendants(VALUE klass, bool immediate_only)
/*
* 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
*
* Returns an array of classes where the receiver is the
diff --git a/object.c b/object.c
index 6e739014a1..430f7eafd0 100644
--- a/object.c
+++ b/object.c
@@ -4660,7 +4660,6 @@ InitVM_Object(void)
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 f87cd68be8..0000000000
--- a/spec/ruby/core/class/descendants_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-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 28285705bf..07c34ce9d5 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -738,38 +738,6 @@ class TestClass < Test::Unit::TestCase
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)