Skip to content

Instantly share code, notes, and snippets.

@cwise
Created November 8, 2010 20:19
Show Gist options
  • Save cwise/668196 to your computer and use it in GitHub Desktop.
Save cwise/668196 to your computer and use it in GitHub Desktop.
I want to refactor this method
def streak
return "-" if @played_games.empty?
games=@played_games
streak=0
game=games.pop
last_result=game.result_type(@team.id)
until game.nil? || game.result_type(@team.id)!=last_result do
game=games.pop
streak+=1
end
"#{last_result}#{streak}"
end
@cwise
Copy link
Author

cwise commented Nov 8, 2010

After an afternoon of refactoring, I'm left with this ugly thing. Any thoughts? Basically, the functionality is to take the array of played_games (sorted) and determine a streak identifier from the last result (e.g. W3, L2, T1 etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment