User Guide

Ruby Component
The event Method
As we mentioned earlier, the Ruby Component evaluates your code as you type. If your code contains expressions (as opposed to
declarations or definitions) then these are executed and the last result is displayed in the Output pane.
Outside of the editor your code will also execute whenever data arrives at an input. This allows you to use the Ruby component for data
processing.
This is all extremely useful but what happens if you want to respond to data received at one input differently from data received at another?
Method Definition
For more advanced data handling you can define an event method. This is a special method which FlowBotics Studio looks for whenever it
receives data at an input.
The event method can have up to 3 input parameters:
i - references the input at which the data arrived
v - value that arrived at the input
t - time at which the data arrived (schematic time in seconds)
You can have 0,1,2 or all 3 input parameters but you must add them in the order. So for example, you can have no parameters or you can
have i on its own or i and v or i and v and t but you can't have v on its own or i and t without v. More on t in the next section, we'll focus on i
and v for now.
The example above shows how you would define an event method that would act as a 'sample and hold'. Data arriving at the first input is
stored. Any trigger at the second input results in the last value being sent out.
If you don't supply a v input and just have a connector reference then you won't be passed any data. The event method will still be called
when data arrives at any of the inputs. You'll know which input got triggered you just won't know what data arrived.
Note that you can name the input parameters whatever you like, you don't have to use i,v and t. However, the method name must always be
event as that's what FlowBotics Studio will be looking for.
Connector Referencing
You might think that the connector reference parameter passed to the event method is an integer value but it is in fact an instance of the
RubyEditConnector class.
Objects of this class can be treated as integer indexes when used in a comparison situation. However, under the hood the class not only
encapsulates the connector index but also any connector label that you may have assigned.
107 of 212