Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Class#descendants #5309

Merged
merged 1 commit into from Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 0 additions & 15 deletions NEWS.md
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions class.c
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion object.c
Expand Up @@ -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");
Expand Down
38 changes: 0 additions & 38 deletions spec/ruby/core/class/descendants_spec.rb

This file was deleted.

32 changes: 0 additions & 32 deletions test/ruby/test_class.rb
Expand Up @@ -738,38 +738,6 @@ def test_assign_frozen_class_to_const
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)
Expand Down