Closed guardianblue closed 11 years ago
Interesting idea. I've implemented a little more generic way of doing conditional logic to dictate whether or not a member should be ranked in the leaderboard. The lambda would be passed the member, current score, score and the member data.
You can find this code in the version-3-proposal-rank-member-if branch. From the README in that proposal:
highscore_check = lambda do |member, current_score, score, member_data|
return true if current_score.nil?
return true if score > current_score
false
end
highscore_lb.rank_member_if(highscore_check, 'david', 1337)
highscore_lb.score_for('david')
=> 1337.0
highscore_lb.rank_member_if(highscore_check, 'david', 1336)
highscore_lb.score_for('david')
=> 1337.0
highscore_lb.rank_member_if(highscore_check, 'david', 1338)
highscore_lb.score_for('david')
=> 1338.0
Yes, allow user to pass a block is much more generic. Nice!
By the way, I think I have made a mistake with the determination of "better"
Correct code should be:
better = (!old_score) || (@reverse ? (score < old_score) : (score > old_score))
Updated the code to add a final parameter passed to the rank_conditional with the leaderboard options.
Code from the version-3-proposal-rank-member-if branch has been merged into the version-3 branch. I'll probably release 3.0.0.rc3 with this functionality and then finally release 3.0.0, but you can start using this functionality now from the version-3 branch.
Currently,
rank_member
method overwrites existing score. However, sometimes we want to update the score only if the new one is better.Below is the suggested code for this feature.