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

Document `.descendants` and `.subclasses` advice

Open alexanderadam opened this issue 3 months ago • 0 comments

A wise man, let's call him Ben, once said:

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.

And I totally trust him on that because he's making a… GoodJob :drum:

This is generally unwanted to be documented in Rails. But I also understand Ben's reasoning.

Now the question is: do you want to have it here? Shall I add the cops (1, 2) here? :thinking:

PS: I'm looking for a new adventure in case anybody is looking to hire or work with a Ruby/Rails/Crystal dev

alexanderadam avatar Oct 21 '25 18:10 alexanderadam