Last active
August 29, 2015 14:22
-
-
Save dasibre/b35164c876f7e6d1db2c to your computer and use it in GitHub Desktop.
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
| class Ranking | |
| attr_reader :rankings, :current_rank | |
| def initialize | |
| @rankings = [-8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8] | |
| @rank_index = 0 | |
| @current_rank = rankings[@rank_index] | |
| end | |
| def up | |
| return "Already at highest rank" if @rank_index == 15 | |
| @current_rank = rankings[@rank_index += 1] | |
| end | |
| def down | |
| return "Already at lowest rank" if @rank_index == 0 | |
| @current_rank = rankings[@rank_index -= 1] | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simplified Version
class Ranking
def initialize
@current_rank = -8
end
def up
return "Already highest Rank" if @current_rank == 8
@current_rank == -1 ? @current_rank += 2 : @current_rank += 1
end
def down
return "At lowest Rank" if @current_rank == -8
@current_rank == 1 ? @current_rank -= 2 : @current_rank -= 1
end
def current
@current_rank
end
end