Module: HTAuth::DescendantTracker
- Included in:
- Algorithm
- Defined in:
- lib/htauth/descendant_tracker.rb
Overview
Use by either
class Foo
extend DescendantTracker
end
or
class Foo
class << self
include DescendantTracker
end
end
It will track all the classes that inherit from the extended class and keep them in a Set that is available via the ‘children’ method.
Instance Method Summary collapse
-
#children ⇒ Object
The list of children that are registered.
-
#find_child(method, *args) ⇒ Object
find the child that returns truthy for then given method and parameters.
- #inherited(klass) ⇒ Object
Instance Method Details
#children ⇒ Object
The list of children that are registered
29 30 31 32 33 34 |
# File 'lib/htauth/descendant_tracker.rb', line 29 def children unless defined? @children @children = Array.new end return @children end |
#find_child(method, *args) ⇒ Object
find the child that returns truthy for then given method and parameters
40 41 42 43 44 |
# File 'lib/htauth/descendant_tracker.rb', line 40 def find_child( method, *args ) children.find do |child| child.send( method, *args ) end end |
#inherited(klass) ⇒ Object
21 22 23 24 |
# File 'lib/htauth/descendant_tracker.rb', line 21 def inherited( klass ) return unless klass.instance_of?( Class ) self.children << klass end |