simple state machine in Ruby
Posted: Thu May 03, 2012 2:33 pm
Here is something that I had been wanting to do, as well as others.
It's a simple state machine in a Ruby code block, that illustrates a couple important concepts and uses the event method. The first and second inputs are external event triggers, and the 101st and 102nd are "internal" triggers. The 2nd set of numbering is irrelevant, but is set aside at a high number so that more external events can be added later.
Basically, to transition from state 1 to state 2, input 101 event is triggered by the timer reaching 2 seconds. The states work through accordingly. This also is a good illustration of using timer's in a Ruby block.
It's a simple state machine in a Ruby code block, that illustrates a couple important concepts and uses the event method. The first and second inputs are external event triggers, and the 101st and 102nd are "internal" triggers. The 2nd set of numbering is irrelevant, but is set aside at a high number so that more external events can be added later.
Basically, to transition from state 1 to state 2, input 101 event is triggered by the timer reaching 2 seconds. The states work through accordingly. This also is a good illustration of using timer's in a Ruby block.