Skip to content

Instantly share code, notes, and snippets.

@libryder
Last active December 11, 2015 07:59
Show Gist options
  • Save libryder/5c5bf6460eb0887fea10 to your computer and use it in GitHub Desktop.
Save libryder/5c5bf6460eb0887fea10 to your computer and use it in GitHub Desktop.
class UserLevel
attr_reader :user
attr_accessor :level
LEVELS = {
1: 5,
2: 10,
3: 25,
4: 40
}
def initialize(user)
@user = user
calculate_level
end
private
def calculate_level(user_points)
LEVELS.keys.each_pair do |numeric_level, points |
if user_points >= points
self.level = numeric_level
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment