Last active
November 25, 2015 14:12
-
-
Save rishabg/1069771 to your computer and use it in GitHub Desktop.
AR Loop test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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