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Â Â Â &...