Active Support 後代追蹤器
此模組提供內部實作來追蹤後代,速度比反覆運算 ObjectSpace
快。
不過,Ruby 3.1 提供快速的原生 +Class#subclasses+ 方法,因此如果知道你的程式碼不會在舊版 Ruby 上執行,包含 ActiveSupport::DescendantsTracker
不會提供任何好處。
方法
類別公開方法
descendants(klass) 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/descendants_tracker.rb, line 104 def descendants(klass) klass.descendants end
subclasses(klass) 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/descendants_tracker.rb, line 100 def subclasses(klass) klass.subclasses end
實例公開方法
descendants() 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/descendants_tracker.rb, line 109 def descendants subclasses = DescendantsTracker.reject!(self.subclasses) subclasses.concat(subclasses.flat_map(&:descendants)) end
subclasses() 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/descendants_tracker.rb, line 175 def subclasses DescendantsTracker.subclasses(self) end