Created
          November 8, 2010 20:19 
        
      - 
      
- 
        Save cwise/668196 to your computer and use it in GitHub Desktop. 
    I want to refactor this method
  
        
  
    
      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
    
  
  
    
  | 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 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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).