Module: Launchy::DescendantTracker
- Included in:
- Application, Launchy::Detect::HostOsFamily, Launchy::Detect::NixDesktopEnvironment, OSFamily
- Defined in:
- lib/launchy/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 one of the child classes by calling the given method and passing all the rest of the parameters to that method in each child.
- #inherited(klass) ⇒ Object
Instance Method Details
#children ⇒ Object
The list of children that are registered
35 36 37 38 |
# File 'lib/launchy/descendant_tracker.rb', line 35 def children @children = [] unless defined? @children @children end |
#find_child(method, *args) ⇒ Object
Find one of the child classes by calling the given method and passing all the rest of the parameters to that method in each child
44 45 46 47 48 49 |
# File 'lib/launchy/descendant_tracker.rb', line 44 def find_child(method, *args) children.find do |child| Launchy.log "Checking if class #{child} is the one for #{method}(#{args.join(', ')})}" child.send(method, *args) end end |
#inherited(klass) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/launchy/descendant_tracker.rb', line 25 def inherited(klass) super return unless klass.instance_of?(Class) children << klass end |