Class: Roster
- Inherits:
-
Object
- Object
- Roster
- Defined in:
- lib/roster.rb
Instance Attribute Summary collapse
-
#teams ⇒ Object
readonly
Returns the value of attribute teams.
Instance Method Summary collapse
- #enroll(player) ⇒ Object
-
#initialize ⇒ Roster
constructor
A new instance of Roster.
Constructor Details
#initialize ⇒ Roster
Returns a new instance of Roster.
4 5 6 |
# File 'lib/roster.rb', line 4 def initialize @teams = [] end |
Instance Attribute Details
#teams ⇒ Object (readonly)
Returns the value of attribute teams.
2 3 4 |
# File 'lib/roster.rb', line 2 def teams @teams end |
Instance Method Details
#enroll(player) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/roster.rb', line 8 def enroll(player) team_name = player.team team = @teams.find { |team| team.name == team_name } unless team team = Team.new(team_name) @teams << team end team.enlist(player) end |