rubocop-github icon indicating copy to clipboard operation
rubocop-github copied to clipboard

New Cop: Avoid usage of `Class.descendents`

Open bensheldon opened this issue 3 years ago • 2 comments

There are two reasons why this is an unreliable solution:

  • it doesn't know about things that have yet to be autoloaded
  • it's non-deterministic with regards to Garbage Collection of classes. If you use Class.descendants in Test, where there is a pattern to dynamically define classes, GC is unpredictable for when those classes are cleaned up and removed by the GC.

cc @jhawthorn

bensheldon avatar Aug 04 '22 17:08 bensheldon

Is this still relevant with AS's DescendantsTracker and the removal of the Ruby implementation?

alexanderadam avatar Oct 21 '25 16:10 alexanderadam

Yes. The reasons for not using 'descendants' are still valid regardless of how descendants is implemented.

Edit: oh sorry, didn't see this was the GitHub rubocop 🖖🏻

bensheldon avatar Oct 21 '25 16:10 bensheldon