Skip to content

Commit 4c3d17f

Browse files
committed
Update README.adoc
1 parent 86bffd4 commit 4c3d17f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,24 @@ end
745745

746746
Check the https://github.com/norman/friendly_id[gem documentation] for more information about its usage.
747747

748+
=== Avoid `Class#descendants` [[avoid-class-descendants]]
749+
750+
Avoid using `Class#descendants` as it is unreliable.
751+
It doesn't know about things that have yet to be autoloaded.
752+
It's non-deterministic with regards to Garbage Collection of classes. If you use `Class#descendants` in tests, where there is a pattern to dynamically define classes, GC is unpredictable for when those classes are cleaned up and removed by the GC.
753+
754+
[source,ruby]
755+
----
756+
# bad
757+
class Person < ApplicationRecord
758+
end
759+
760+
class Employee < Person
761+
end
762+
763+
Person.descendants # => Unreliable, may or may not include Employee
764+
----
765+
748766
=== `find_each` [[find-each]]
749767

750768
Use `find_each` to iterate over a collection of AR objects.

0 commit comments

Comments
 (0)