Rails 3 State Machine
class TrafficLight < ActiveRecord::Base
include ActiveRecord::StateMachine
state_machine do
state :red
state :green
state :yellow
event :change_color do
transitions :to => :red, :from => [:yellow], :on_transition => :catch_runners
transitions :to => :yellow, :from => [:green]
transitions :to => :green, :from => [:red]
end
end
def catch_runners
puts "That'll be $250."
end
end