Skip to content

Instantly share code, notes, and snippets.

@kineticac
Created July 12, 2011 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kineticac/1079126 to your computer and use it in GitHub Desktop.
Save kineticac/1079126 to your computer and use it in GitHub Desktop.
custom unique method for coach arrays
def self.unique(coaches)
return coaches if coaches.empty?
raise ArgumentError, "requires array of coaches as an argument" if(coaches.class != Array || coaches.first.class != Coach)
coach_ids = []
unique_coaches = []
coaches.each do |coach|
unless coach_ids.include?(coach.id)
coach_ids << coach.id
unique_coaches << coach
end
end
return unique_coaches
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment