Module: RobotLab::Runnable
Overview
Shared interface for things you can run with a message: a single Robot or a
multi-robot Network. It lets callers treat them uniformly instead of
branching on is_a?(RobotLab::Network) — which otherwise spreads concrete
type knowledge across every consumer.
Implementers provide:
- #run(message = nil, **opts) — execute with the given message (both Robot
and Network accept a positional message and keyword options)
- #crew — the constituent robots, as an Array
- #network? — true for a multi-robot network
The rest (chief, robot_count, single?) derive from those.
Instance Method Summary collapse
-
#chief ⇒ Robot?
The lead robot — the chief of the crew.
-
#crew ⇒ Array<Robot>
The constituent robots as an Array.
-
#network? ⇒ Boolean
True for a multi-robot network.
-
#robot_count ⇒ Integer
Number of constituent robots.
-
#single? ⇒ Boolean
True for a single robot.
Instance Method Details
#chief ⇒ Robot?
The lead robot — the chief of the crew.
32 33 34 |
# File 'lib/robot_lab/runnable.rb', line 32 def chief crew.first end |
#crew ⇒ Array<Robot>
The constituent robots as an Array. A single Robot is a crew of one.
25 26 27 |
# File 'lib/robot_lab/runnable.rb', line 25 def crew raise NotImplementedError, "#{self.class} must implement #crew" end |
#network? ⇒ Boolean
Returns true for a multi-robot network.
42 43 44 |
# File 'lib/robot_lab/runnable.rb', line 42 def network? false end |
#robot_count ⇒ Integer
Returns number of constituent robots.
37 38 39 |
# File 'lib/robot_lab/runnable.rb', line 37 def robot_count crew.size end |
#single? ⇒ Boolean
Returns true for a single robot.
47 48 49 |
# File 'lib/robot_lab/runnable.rb', line 47 def single? !network? end |