Skip to content

Instantly share code, notes, and snippets.

@dasibre
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save dasibre/b35164c876f7e6d1db2c to your computer and use it in GitHub Desktop.

Select an option

Save dasibre/b35164c876f7e6d1db2c to your computer and use it in GitHub Desktop.
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
@dasibre

dasibre commented Jun 9, 2015

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment