Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,25 @@ end

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

=== Avoid `Class#descendants` and `Class#subclasses` [[avoid-class-descendants]]

Avoid using `Class#descendants` and `Class#subclasses` as they are unreliable for several reasons:

* They don't know about things that have yet to be autoloaded
* They're non-deterministic with regards to Garbage Collection of classes. If you use `Class#descendants` or `Class#subclasses` 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.

[source,ruby]
----
# bad
class Person < ApplicationRecord
end

class Employee < Person
end

Person.descendants # => Unreliable, may or may not include Employee
----

=== `find_each` [[find-each]]

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