find(:all)
games.each do |game|
highest_win=nil
game.wins.each do |win|
highest_win = win if highest_win.nil? or
win.quantity > highest_win.quantity
end
puts "#{game.name}: #{highest_win.player.name} with #{highest_win.quantity} wins"
end
players = Player.find(:all)
highest_winning_player = nil
players.each do |player|
highest_winning_player = player if
highest_winning_player.nil? or
player.total_wins > highest_winning_player.total_wins
end
puts "Highest Winning Player: #{highest_winning_player.name} " <<
"with #{highest_winning_player.total_wins} wins"
Save this script as player_wins.rb. You can run this script using the following
command:
ruby player_wins.rb
CHAPTER 1 n DATA ACCESS FUNDAMENTALS 14
Eagle Beagle Ballad: Matthew 'Iron Helix' Bouley with 8 wins
Camel Tender Redux: Matthew 'Iron Helix' Bouley with 13 wins
Super Dunkball II: The Return: Luke 'Cable Boy' Bouley with 15 wins
Turn the Corner SE: Carrera vs CRX: Matthew 'm_giff' Gifford with 9 wins
Highest Winning Player: Matthew 'Iron Helix' Bouley with 31 wins
Let??™s take a look at each of the techniques used in this script.
Pages:
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49