Sha256: 135a0150059ca714e6c43d0d9f10e1e1f75e47d9d848eb85f6482404603b6a47
Contents?: true
Size: 1.13 KB
Versions: 69
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true class ReeEnum::Value attr_reader :enum_class, :enum_name, :value, :label, :number contract(Class, Symbol, Symbol, Integer, Nilor[String] => Any) def initialize(enum_class, enum_name, value, number, label) @enum_class = enum_class @enum_name = enum_name @value = value @label = label @number = number end def to_s @value.to_s end def to_sym @value end def to_i @number end def as_json(*args) to_s end def label @label end contract(Or[ReeEnum::Value, Symbol, Integer, Any] => Bool) def ==(compare) if compare.is_a?(self.class) @value == compare.value else @value == compare || @number == compare end end contract(Or[ReeEnum::Value, String, Integer] => Bool) def <=>(other) if other.is_a?(self.class) @number <=> other.number elsif other.is_a?(Symbol) @value == other elsif other.is_a?(Integer) @number == other else raise ArgumentError.new("unable to compare ReeEnum::Value with other classes") end end def inspect "#{enum_class.name}##{@value.to_s}" end end
Version data entries
69 entries across 69 versions & 1 rubygems