Skip to content

Instantly share code, notes, and snippets.

@razielgn
Created June 10, 2013 21:44
Show Gist options
  • Save razielgn/5752643 to your computer and use it in GitHub Desktop.
Save razielgn/5752643 to your computer and use it in GitHub Desktop.
Trying to isolate the state_machine SystemStackError rubinius bug.
require_relative 'lib/state_machine'
class TrafficLight
state_machine :initial => :stop do
event :cycle do
transition :stop => :proceed, :proceed => :caution, :caution => :stop
end
state :stop do
def color(transform)
value = 'red'
if block_given?
yield value
else
value.send(transform)
end
value
end
end
state all - :proceed do
def capture_violations?
true
end
end
state :proceed do
def color(transform)
'green'
end
def capture_violations?
false
end
end
state :caution do
def color(transform)
'yellow'
end
end
end
def color(transform = :to_s)
super
end
end
1.upto(10**5) do
@light = TrafficLight.new
@light.state = 'caution'
@light.color
@light.capture_violations?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment