module Listen::FSM::ClassMethods
Public Instance Methods
start_state(new_start_state = nil)
click to toggle source
Obtain or set the start state Passing a state name sets the start state
# File lib/listen/fsm.rb, line 17 def start_state(new_start_state = nil) if new_start_state new_start_state.is_a?(Symbol) or raise ArgumentError, "state name must be a Symbol (got #{new_start_state.inspect})" @start_state = new_start_state else defined?(@start_state) or raise ArgumentError, "`start_state :<state>` must be declared before `new`" @start_state end end
state(state_name, to: nil, &block)
click to toggle source
Declare an FSM
state and optionally provide a callback block to fire on state entry Options:
-
to: a state or array of states this state can transition to
# File lib/listen/fsm.rb, line 35 def state(state_name, to: nil, &block) state_name.is_a?(Symbol) or raise ArgumentError, "state name must be a Symbol (got #{state_name.inspect})" states[state_name] = State.new(state_name, to, &block) end