Class: FunctionalLightService::EnumBuilder::DataType
- Defined in:
- lib/functional-light-service/functional/enum.rb
Defined Under Namespace
Modules: AnyEnum, Binary, Nullary
Class Method Summary collapse
-
.create(parent, args) ⇒ Object
rubocop:disable Metrics/MethodLength.
Class Method Details
.create(parent, args) ⇒ Object
rubocop:disable Metrics/MethodLength
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/functional-light-service/functional/enum.rb', line 69 def self.create(parent, args) if args.include? :value raise ArgumentError, "#{args} may not contain the reserved name :value" end dt = Class.new(parent) dt.instance_eval do public_class_method :new include AnyEnum define_method(:args) { args } define_method(:parent) { parent } private :parent end case args.count when 0 dt.instance_eval do include Nullary private :value end when 1 dt.instance_eval do define_method(args[0].to_sym) { value } end else dt.instance_eval do include Binary args.each do |m| define_method(m) do @value[m] end end end end dt end |