Skip to content

Instantly share code, notes, and snippets.

@rishabg
Last active November 25, 2015 14:12
Show Gist options
  • Save rishabg/1069771 to your computer and use it in GitHub Desktop.
Save rishabg/1069771 to your computer and use it in GitHub Desktop.
AR Loop test
# 1. Briefly explain what the following code does.
# 2. Is there anything wrong with it?
# 3. How would you resolve the problems (if any exist)?
# Assume League, Team, Player models
# League <has_many> teams
# Team <has_many> players
# Player has boolean column all_star
def all_stars(league_name)
league = League.find_by_name league_name
all_stars = []
league.teams.each do |team|
team.players.each do |player|
all_stars << player if player.all_star?
end
end
all_stars
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment