Skip to content

Instantly share code, notes, and snippets.

@efremidze
Last active March 12, 2017 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efremidze/7c1134a013e26c15e137189eabfc32a1 to your computer and use it in GitHub Desktop.
Save efremidze/7c1134a013e26c15e137189eabfc32a1 to your computer and use it in GitHub Desktop.
import Foundation
typealias Points = Int
extension Points {
func rank() -> Rank {
return Rank(self)
}
}
enum Rank {
case Recruit, Rookie, Pro
init(_ points: Points) {
switch points {
case 0..<100:
self = .Recruit
case 100..<200:
self = .Rookie
default:
self = .Pro
}
}
}
// demo
let rank = 10.rank()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment