class ElectionVote
attr_reader :votes
attr_reader :candidates
-
+
def initialize(votes=nil)
@votes = Hash.new unless defined?(@votes)
@candidates = Array.new unless defined?(@candidates)
def tally_vote
self.verify_vote(vote)
end
+
+ def filter_out(winner)
+ @candidates.delete_if {|x| winner.winners.include?(x)}
+ end
+
end
class PluralityVote < ElectionVote
protected
def verify_vote(vote=nil)
- vote ? true : false
+ vote.instance_of?( String )
end
def tally_vote(candidate)
class ElectionResult
attr_reader :winners
-
+ attr_reader :election
+
def initialize(voteobj=nil)
unless voteobj and voteobj.kind_of?( ElectionVote )
raise ArgumentError, "You must pass a ElectionVote array.", caller