Class: Deterministic::EnumBuilder::DataType
- Defined in:
- lib/deterministic/enum.rb
Defined Under Namespace
Modules: AnyEnum, Binary, Nullary
Class Method Summary collapse
Class Method Details
.create(parent, name, args) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/deterministic/enum.rb', line 54 def self.create(parent, name, args) raise ArgumentError, "#{args} may not contain the reserved name :value" if args.include? :value dt = Class.new(parent) dt.instance_eval { class << self; public :new; end include AnyEnum define_method(:args) { args } define_method(:parent) { parent } private :parent } if args.count == 0 dt.instance_eval { include Nullary private :value } elsif args.count == 1 dt.instance_eval { define_method(args[0].to_sym) { value } } else dt.instance_eval { include Binary args.each do |m| define_method(m) do @value[m] end end } end dt end |