Sha256: a00b482e2030dee1c517f23eaac952d10b58220f309e5b0972c482e969ab7465
Contents?: true
Size: 708 Bytes
Versions: 1
Compression:
Stored size: 708 Bytes
Contents
require 'inflecto' require_relative 'enum/version' module Rasti module Enum class Value < String def initialize super Inflecto.underscore(Inflecto.demodulize(self.class.name)).upcase end end def values @values ||= included_classes.map(&:new) end def [](value) values.detect { |e| e == value.to_s } || raise("Invalid value #{value} for #{name}") end def include?(value) values.any? { |e| e == value.to_s } end private def class_constants constants.select { |c| const_get(c).is_a? Class }.sort end def included_classes @included_classes ||= class_constants.map { |c| const_get(c) } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rasti-enum-1.0.0 | lib/rasti/enum.rb |