Module: DeviceControl::Updateable
- Included in:
- Controller, Device, Smoother
- Defined in:
- lib/device_control.rb
Overview
There is a pattern for how both Controllers (e.g. thermostat) and Devices
(e.g. heater) operate.
They each have an input varying over time which determines the output. A thermostat (Controller) listens for temperature and tells the heater how high to turn it up (or just on / off). A heater (Device) listens to its control knob and yields heat as an output.
We capture this pattern with a single method: update. It accepts the latest input and provides an output based on the input. When the input is read in, perhaps some internal state is changed on the processor which will affect the output.
Any class which mixes in Updateable can define its own input= method, which may update any ivars. Any such class must define an output method.
Instance Method Summary collapse
Instance Method Details
#update(val) ⇒ Object
18 19 20 21 |
# File 'lib/device_control.rb', line 18 def update(val) self.input = val self.output end |