Skip to content

Instantly share code, notes, and snippets.

@yawboakye
Created August 10, 2012 14:51
Show Gist options
  • Save yawboakye/3314760 to your computer and use it in GitHub Desktop.
Save yawboakye/3314760 to your computer and use it in GitHub Desktop.
A win for @abocco in the GYAC
module GhanaYouthAwardsCeremony
extend self
def notify_aboccos_boys
(@candidates.values.max + 10).times { vote_for :abocco }
end
private :notify_aboccos_boys
def vote_for candidate
@candidates ||= Hash.new 0
if @candidates.has_key? candidate
@candidates[candidate] += 1
else
@candidates[candidate] = 1
end
# notify Abboco's boys that someone just voted so they should do something about it..
# Don't blame me, I'm not evil. I'm just helping
notify_aboccos_boys unless candidate == :abocco
end
def display_results
@candidates.each {
|candidate, votes|
puts "#{candidate} received #{votes} vote(s)"
}
end
end
# As a good citizen, I cast just one vote
GhanaYouthAwardsCeremony.vote_for :abocco
# and wait for everybody to vote for their candidates
#
#
#
#
# and then display the results.. If you could read the code above
# you understand what will happen. Good news!!
GhanaYouthAwardsCeremony.display_results
@yawboakye
Copy link
Author

What do you say? e-Voting starts like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment