Module: ClassyEnum
- Defined in:
- lib/classy_enum.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.included(other) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/classy_enum.rb', line 50 def self.included(other) other.extend ClassMethods other.const_set("OPTION_HASH", Hash.new) other::OPTIONS.each do |option| klass = Class.new(ClassyEnumValue) do include other::InstanceMethods if other.const_defined?("InstanceMethods") extend other::ClassMethods if other.const_defined?("ClassMethods") end Object.const_set("#{other}#{option.to_s.camelize}", klass) instance = klass.new(option, other::OPTIONS.index(option)) other::OPTION_HASH[option] = other::OPTION_HASH[option.to_s.downcase] = instance ClassyEnum.const_set(option.to_s.upcase, instance) unless ClassyEnum.const_defined?(option.to_s.upcase) end end |