Class: Finity::State
- Inherits:
-
Object
- Object
- Finity::State
- Defined in:
- lib/finity/state.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#cycle(object) ⇒ Object
Executed if a state is kept during a cycle.
-
#enter(object) ⇒ Object
Executed when the current state is entered.
-
#initialize(name, options = {}) ⇒ State
constructor
Initialize a new state for the state machine with callbacks.
-
#leave(object) ⇒ Object
Executed when the current state is left.
Constructor Details
#initialize(name, options = {}) ⇒ State
Initialize a new state for the state machine with callbacks.
28 29 30 31 |
# File 'lib/finity/state.rb', line 28 def initialize name, = {} @name, @enter, @cycle, @leave = name, *.values_at(:enter, :cycle, :leave) instance_eval &block if block_given? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/finity/state.rb', line 25 def name @name end |
Instance Method Details
#cycle(object) ⇒ Object
Executed if a state is kept during a cycle.
39 40 41 |
# File 'lib/finity/state.rb', line 39 def cycle object execute object, @cycle unless @cycle.nil? end |
#enter(object) ⇒ Object
Executed when the current state is entered.
34 35 36 |
# File 'lib/finity/state.rb', line 34 def enter object execute object, @enter unless @enter.nil? end |
#leave(object) ⇒ Object
Executed when the current state is left.
44 45 46 |
# File 'lib/finity/state.rb', line 44 def leave object execute object, @leave unless @leave.nil? end |