Class: Finity::State

Inherits:
Object
  • Object
show all
Defined in:
lib/finity/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {}
  @name, @enter, @cycle, @leave = name, *options.values_at(:enter, :cycle, :leave)
  instance_eval &block if block_given?
end

Instance Attribute Details

#nameObject

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