fm = FiniteMachine.new do
initial :red
event :ready, :red => :yellow
event :go, :yellow => :green
event :stop, :green => :red
on_before(:ready) { |event| ... }
on_after(:go) { |event| ... }
on_enter(:yellow) { |event| ... }
on_transition { |event| ... }
on_exit(:green) { |event| ... }
end
fm.current # => :red
fm.ready
fm.current # => :yellow
Value flexibility and maintainabilty? Since FiniteMachine is just an object it allows for easy integration with the rest of the system.
If you want simplicity and readability, FiniteMachine provides a natural DSL for declaring events, callbacks and exception handlers.
Transition guard conditions paired with dynamic conditional branching allow for modelling any state flows.