Skip to content

Instantly share code, notes, and snippets.

@axgle
Created November 4, 2009 01:47
Show Gist options
  • Save axgle/225692 to your computer and use it in GitHub Desktop.
Save axgle/225692 to your computer and use it in GitHub Desktop.
#http://github.com/pluginaweek/state_machine
require 'state_machine'
class A
state_machine :initial=>:stop do
event :change do
transition :stop=>:start,:start=>:stop
end
before_transition do |a,_|
p [:before,a.state]
end
after_transition :on=>:change do |a,t|
a.info
end
end
def info
p [:after,@state]
end
end
a=A.new
p a.state
2.times do
a.change
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment