A method that calculates win streaks Right now, I have the following:


A win_streak column on the User table.
This method in game.rb


I'm interpreting win_streak as follows:


The number if the number games in the streak
The value (positive or negative) specifies whether those games were wins (positive) or losses (negative)


game.rb:

def adjust_streak
  u = self.user
  case self.result
    when 'Win'
      u.win_streak &gt; 0 ? u.win_streak += 1 : u.win_streak = 1
    when 'Loss'
      u.win_streak &gt; 0 ? u.win_streak = -1 : u.win_streak -= 1
    end
  u.save
end


I'm looking for a cleaner, and more succinct way to do this (e.g. keep track of win/loss streaks).
You can use Array#min and Array#max to calculate the win/lose streak;
You don't need to use self on getters;
And you can use user.update instead of assigning and calling .save;
I would also rename the win_streak column to streak;




def adjust_streak
  streak = case result
           when 'Win'  then [user.streak, 0].max + 1
           when 'Loss' then [user.streak, 0].min - 1
           end

  user.update streak: streak
end