Created
September 3, 2013 14:42
-
-
Save geku/6424877 to your computer and use it in GitHub Desktop.
Demo State Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Baba | |
state_machine :initial => :parked do | |
event :ignite do | |
transition :parked => :idling, :if => :ignite_car | |
transition :parked => :ignition_failed | |
end | |
event :park do | |
transition :idling => :parked | |
end | |
# before_transition :on => :ignite, :do => lambda {|b| puts "+ before_transition :ignite"; ap b } | |
# before_transition :on => :ignite, :do => :process_ignite | |
# after_failure :on => :ignite, :do => :handle_ignite_failure | |
# after_transition :on => :ignite, :do => lambda {|b| puts "+ after_transition :ignite"; ap b } | |
# after_transition :on => :park, :do => lambda {|b| puts "+ after_transition :park"; ap b } | |
end | |
def ignite_car | |
# do some stuff | |
false | |
end | |
# def handle_ignite_failure(transition) | |
# ap "+ handle_ignite_failure" | |
# ap transition | |
# ignite_failure | |
# end | |
# def process_ignite(transition) | |
# ap "+ process_ignite" | |
# ap transition | |
# throw :halt | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment