Class: Etsm::StateMachine
- Inherits:
-
Object
- Object
- Etsm::StateMachine
- Defined in:
- lib/etsm.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#in_transition ⇒ Object
readonly
Returns the value of attribute in_transition.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
-
#initialize(owner) ⇒ StateMachine
constructor
A new instance of StateMachine.
- #IsIn(state) ⇒ Object
- #Transition(state) ⇒ Object
Constructor Details
#initialize(owner) ⇒ StateMachine
Returns a new instance of StateMachine.
43 44 45 46 47 |
# File 'lib/etsm.rb', line 43 def initialize(owner) @owner = owner @current = nil @in_transition = false end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
40 41 42 |
# File 'lib/etsm.rb', line 40 def current @current end |
#in_transition ⇒ Object (readonly)
Returns the value of attribute in_transition.
41 42 43 |
# File 'lib/etsm.rb', line 41 def in_transition @in_transition end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
39 40 41 |
# File 'lib/etsm.rb', line 39 def owner @owner end |
Instance Method Details
#IsIn(state) ⇒ Object
70 71 72 |
# File 'lib/etsm.rb', line 70 def IsIn(state) return state == @current end |
#Transition(state) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/etsm.rb', line 49 def Transition(state) if @in_transition == true return false end @in_transition = true if @current != nil and @current.exit != nil @current.exit.call end @current = state if @current != nil and @current.enter != nil @current.enter.call end @in_transition = false return true end |