Class: Roster

Inherits:
Object
  • Object
show all
Defined in:
lib/roster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoster

Returns a new instance of Roster.



4
5
6
# File 'lib/roster.rb', line 4

def initialize
  @teams = []
end

Instance Attribute Details

#teamsObject (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