struct FSM::State
- FSM::State
- Struct
- Value
- Object
Overview
Represents a state within the finite state machine.
@property id [String] The unique identifier of the state. @property transitions [Hash(String, Transition)] A collection of transitions associated with the state. @property entry_callbacks [Callable(String, Context)?] Optional callback to be executed when entering the state. @property exit_callbacks [Callable(String, Context)?] Optional callback to be executed when exiting the state.
Defined in:
fsm/state.crClass Method Summary
-
.create(id : String)
Create a new state with the given identifier.
-
.create(id : String, &)
Create a new state with the given identifier and execute a block to set up additional configurations.
Instance Method Summary
-
#==(other : State)
Compare two states for equality based on their identifiers.
-
#all_target_states : Array(String)
Get a list of all target states reachable through transitions from this state.
-
#id : String
The unique identifier of the state.
-
#on_entry(&block : String, Context -> ) : self
Register a new callback to be fired when entering this state.
-
#on_event(event : String, target : String) : self
Register a new transition from this state to another state.
-
#on_event(event : String, target : String, &) : self
Register a new transition with a callback to be executed when the transition is made.
-
#on_exit(&block : String, Context -> ) : self
Register new callbacks to be fired when exiting this state.
Class Method Detail
Create a new state with the given identifier.
@param id [String] The unique identifier of the state.
Create a new state with the given identifier and execute a block to set up additional configurations.
@param id [String] The unique identifier of the state. @yieldparam self [State] The state instance to be configured.
Instance Method Detail
Compare two states for equality based on their identifiers.
@param other [State] The state to compare with.
Get a list of all target states reachable through transitions from this state.
Register a new callback to be fired when entering this state.
@yieldparam event [String] The event triggering the entry callback. @yieldparam context [Context] The context associated with the state machine.
Register a new transition from this state to another state.
@param event [String] The event triggering the transition. @param target [String] The target state after the transition.
Register a new transition with a callback to be executed when the transition is made.
@param event [String] The event triggering the transition. @param target [String] The target state after the transition. @yieldparam event [String] The event triggering the transition. @yieldparam context [Context] The context associated with the state machine.
Register new callbacks to be fired when exiting this state.
@yieldparam event [String] The event triggering the exit callbacks. @yieldparam context [Context] The context associated with the state machine.