1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Remove Class#descendants

This commit is contained in:
Jeremy Evans 2021-12-20 08:26:14 -08:00
parent c57ac4c6e0
commit 3bd5f27f73
Notes: git 2021-12-21 04:02:40 +09:00
5 changed files with 0 additions and 111 deletions

15
NEWS.md
View file

@ -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

25
class.c
View file

@ -1427,31 +1427,6 @@ class_descendants(VALUE klass, bool immediate_only)
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

View file

@ -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");

View file

@ -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

View file

@ -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)