Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # Voter Simulator.
  2. @@political_party = {"D" => "Democrat", "R" => "Republican"}
  3. @@political_views = {"L" => "Liberal", "C" => "Conservative", "T" => "Tea Party", "S" => "Socialist", "N" => "Neutral"}
  4. # Create a valid person with a name.
  5. class Person
  6. attr_accessor :name
  7. def initialize(args)
  8. @name = args.fetch(:name)
  9. end
  10. end
  11.  
  12. # Represents a valid voter.
  13. class Voter < Person
  14. attr_accessor :political_view
  15. def initialize(args)
  16. super(args)
  17. @political_view = @@political_views[args.fetch(:political_view)]
  18. end
  19. # def set_political_view(political_view)
  20. # @political_view = @@political_views[political_view]
  21. # end
  22. end
  23.  
  24. # Represents a valid politician.
  25. class Politician < Person
  26. attr_accessor :political_party
  27. def initialize(args)
  28. super(args)
  29. @political_party = @@political_party[args.fetch(:political_party)]
  30. end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement