Skip to content

Instantly share code, notes, and snippets.

@pzaich
Created June 19, 2012 01:16
Show Gist options
  • Select an option

  • Save pzaich/2951768 to your computer and use it in GitHub Desktop.

Select an option

Save pzaich/2951768 to your computer and use it in GitHub Desktop.
BaseballTeam Class
class BaseballTeam
def initialize
@lineup = { 1 => { 'Aviles' => 'SS' }, 2 => { 'Pedroia' => '2B' }, 3 => { 'Youkilis' => '1B' },
4 => { 'Ortiz' => 'DH' }, 5 => { 'Middlebrooks' => '3B' }, 6 => { 'Gonzalez' => 'OF' },
7 => { 'Saltalamacchia' => 'C' }, 8 => { 'McDonald' => 'OF' }, 9 => { 'Byrd' => 'OF' },
0 => { 'Lester' => 'P' } }
end
def get_lineup
@lineup
end
def batting_order
order = @lineup.values
player_list = []
order.each do |player|
player_list.concat(player.keys.flatten) unless player.has_value?("P")
end
player_list
end
def substitution(position_num, player_position)
if player_position.values != @lineup[position_num].values
else
@lineup[position_num] = player_position
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment