Sha256: fab41f2d4d1fe68fd128184514ab16c7aa6849147dd2ef192ee49570cf4d45da
Contents?: true
Size: 683 Bytes
Versions: 25
Compression:
Stored size: 683 Bytes
Contents
module Incline class ConstantEnum attr_reader :value, :name def initialize(value) raise ArgumentError, 'Invalid value' unless self.class.named?(value) @value = value @name = self.class.name_for(value) end def to_s name end def self.named?(value) !name_for(value).blank? end def self.name_for(value) names.key(value) || '' end private def self.names @names ||= begin ret = {} constants(false).each do |nm| ret[nm.to_s] = const_get(nm) end ret end end end end
Version data entries
25 entries across 25 versions & 1 rubygems