module TopScore
Constants
- VERSION
Public Class Methods
leaderboard(users)
click to toggle source
returns users ordered by score
# File lib/top_score.rb, line 13 def self.leaderboard(users) users.sort{ |x, y| y.score <=> x.score } end
penalty(current_user, points)
click to toggle source
# File lib/top_score.rb, line 17 def self.penalty(current_user, points) current_user.score -= points current_user.save end
update_score(current_user, points)
click to toggle source
assumes you have a user model also assumes that in that model you've added a column called points in any model you can add points to the score by simply saving TopScore.update_score
(current_user, 10)
# File lib/top_score.rb, line 7 def self.update_score(current_user, points) current_user.score += points current_user.save end