Skip to content

Instantly share code, notes, and snippets.

@havenwood

havenwood/status.rb

Created Jul 21, 2020
Embed
What would you like to do?
Refactoring suggestions for memcorrupt #ruby IRC
class Status
include Comparable
CODES = [['-', :todo], ['x', :doing], ['+', :done]].freeze
SYM = CODES.map(&:first).each_with_index.to_h.freeze
STR = CODES.map(&:last).each_with_index.to_h.freeze
INT = CODES.each_with_index.reduce({}) do |acc, (keys, i)|
acc.merge({i => i}, keys.to_h { |key| [key, i] })
end.freeze
attr_reader :to_i, :to_s, :to_sym
def initialize(stat)
@to_i = INT.fetch(stat)
@to_s = STR.fetch(@to_i)
@to_sym = SYM.fetch(@to_i)
end
def <=>(other)
@to_i <=> other.to_i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.