Skip to content

Instantly share code, notes, and snippets.

@maxim
Created September 9, 2023 17:20
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 maxim/ee976d14c10c72b6991ba196e87940d0 to your computer and use it in GitHub Desktop.
Save maxim/ee976d14c10c72b6991ba196e87940d0 to your computer and use it in GitHub Desktop.
class Severity
include Comparable
attr_reader :value
ORDER = %i[low medium high]
def self.[](value)
new(value)
end
def initialize(value)
@value = value
end
def <=>(other)
ORDER.index(@value) <=> ORDER.index(other.value)
end
def inspect
"Severity[:#{@value}]"
end
end
pp [Severity[:high], Severity[:low]].sort
# Output
# [Severity[:low], Severity[:high]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment