5. Object-Oriented Programming with Ruby
Activity 5.01: Voting Application for Employee of the Month
Solution
- Open the Terminal and clone the Lightweight Terminal Framework from GitHub:
git clone https://github.com/PacktWorkshops/The-Ruby-Workshop/tree/master/Chapter05/Activity5.01/framework
- Implement the
VotingMachine
model class:voting_machine.rb
1 class VotingMachine 2 attr_reader :month, :year, :results 3 4 class InvalidVote < Exception; end 5 6 def initialize(month, year) 7 @month = month 8 @year = year 9 @results = {} 10 end 11 12 def record_vote(voter, votee) 13 raise InvalidVote unless valid_vote?(voter, votee) 14 results[votee] ||= 0 15 &...