Created
September 7, 2014 05:59
-
-
Save jdblack/d3401098c44c37baee82 to your computer and use it in GitHub Desktop.
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
require 'finite_machine' | |
require 'pp' | |
class StopLight < FiniteMachine::Definition | |
events { | |
initial :red | |
event :power_on, :off => :red | |
# event :power_off, :any => :off | |
event :power_off, [:on, :red, :green, :yellow] => :off | |
event :change, :red => :green | |
event :change, :green => :yellow | |
event :change, :yellow => :red | |
} | |
callbacks { | |
on_transition do |event| | |
pp event | |
end | |
} | |
end | |
sl = StopLight.new | |
loop do | |
puts "***Change" | |
sl.change | |
if rand(5) == 0 | |
puts "*** Whoops. Lost power!" | |
sl.power_off | |
end | |
sleep 1 | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment