From: "fxn (Xavier Noria)" Date: 2022-01-24T10:28:09+00:00 Subject: [ruby-core:107254] [Ruby master Feature#18273] Class#subclasses Issue #18273 has been updated by fxn (Xavier Noria). > Sure, and you are entitled to it, I just don't understand how you reconcile it with the existence of weak references. I believe our legitimate differences in view points are: 1. You say it works as expected, based on weak refs. 2. I say, true, but a posteriori, usage is not deterministic for the user, and therefore not a good core API. The documentation should say: Returns the subclasses that have not been yet GCed. Multiple calls may yield different values even if you don't touch the hierarchy in between them. To me, having to write such documentation is a suggesting this feature is dubious. ---------------------------------------- Feature #18273: Class#subclasses https://bugs.ruby-lang.org/issues/18273#change-96115 * Author: byroot (Jean Boussier) * Status: Closed * Priority: Normal ---------------------------------------- Ref: https://github.com/rails/rails/pull/43481 Something we forgot to mention in [Feature #14394], is either a parameter or another method to only get direct descendants. Active Support has been offering `Class.subclasses` as: ```ruby def subclasses descendants.select { |descendant| descendant.superclass == self } end ``` It seems a bit silly to grab all descendants and then restrict the list when `Class#descendants` had to do some recursion to get them all in the first place. ### Proposal We could either implement `Class#subclasses` directly, or accept a parameter in `Class#descendants`, e.g. `descendants(immediate = false)`. cc @eregon -- https://bugs.ruby-lang.org/ Unsubscribe: