Active Support Descendants Tracker¶ ↑
此模块提供了一个内部实现来跟踪后代,这比迭代 ObjectSpace 更快。
然而,Ruby 3.1 提供了快速的原生 +Class#subclasses+ 方法,所以如果你知道你的代码不会在旧版本的 Ruby 上运行,那么包含 ActiveSupport::DescendantsTracker 没有任何好处。
方法
类公共方法
descendants(klass) 链接
源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/descendants_tracker.rb, line 102 def descendants(klass) klass.descendants end
subclasses(klass) 链接
源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/descendants_tracker.rb, line 98 def subclasses(klass) klass.subclasses end
实例公共方法
descendants() 链接
源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/descendants_tracker.rb, line 107 def descendants subclasses = DescendantsTracker.reject!(self.subclasses) subclasses.concat(subclasses.flat_map(&:descendants)) end