Created
December 28, 2010 07:13
-
-
Save Sephi-Chan/756998 to your computer and use it in GitHub Desktop.
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
class Stater | |
def initialize(*roles) | |
@state = 0 | |
@roles = roles | |
end | |
def current | |
@roles[@state % @roles.size] | |
end | |
def next | |
@roles[(@state + 1) % @roles.size] | |
end | |
def next! | |
@state += 1 | |
current | |
end | |
end |
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 'spec_helper' | |
describe Stater do | |
before :all do | |
@stater = Stater.new(:killers, :doctor, :detective) | |
end | |
it "should start with killers round" do | |
@stater.current.should == :killers | |
end | |
it "should be followed by doctor round" do | |
@stater.next.should == :doctor | |
@stater.next!.should == :doctor | |
@stater.current.should == :doctor | |
end | |
it "should be followed by detective round" do | |
@stater.next.should == :detective | |
@stater.next!.should == :detective | |
@stater.current.should == :detective | |
end | |
it "should go back to killers round" do | |
@stater.next.should == :killers | |
@stater.next!.should == :killers | |
@stater.current.should == :killers | |
end | |
it "should be followed by doctor round" do | |
@stater.next.should == :doctor | |
@stater.next!.should == :doctor | |
@stater.current.should == :doctor | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment