Created
June 10, 2013 21:44
-
-
Save razielgn/5752643 to your computer and use it in GitHub Desktop.
Trying to isolate the state_machine SystemStackError rubinius bug.
This file contains 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_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