Skip to content

Instantly share code, notes, and snippets.

@mseymour
Created August 26, 2011 20:37
Show Gist options
  • Save mseymour/1174377 to your computer and use it in GitHub Desktop.
Save mseymour/1174377 to your computer and use it in GitHub Desktop.
Acrobot acro game class (incomplete 2011-08-25 @ 5:37 PM)
module Games
module Acro
class Game
attr_reader :acronym
attr_reader :answers
attr_reader :voters
def initialize acronym = nil
@acronym = acronym ||= Random.new.rand(3..10).times.map { [*?A...?Z].sample }.join
@answers = []
@voters = []
Answer = Struct.new(:answer, :nick, :time, :votes)
end
def add_answer answer, nick
@answers << Answer.new(answer, nick, time.now, 0)
end
def vote! id, nick
raise "You already voted!" if @voters.include?[nick]
@answers[id].votes += 1
end
def decide_winner
@answers.sort {|x,y| y.votes <=> x.votes}.first
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment