Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created December 28, 2010 07:13
Show Gist options
  • Save Sephi-Chan/756998 to your computer and use it in GitHub Desktop.
Save Sephi-Chan/756998 to your computer and use it in GitHub Desktop.
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
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