Module: Renum

Defined in:
lib/renum.rb,
lib/renum/name_serializer.rb,
lib/renum/enumerated_value.rb,
lib/renum/index_serializer.rb,
lib/renum/enumerated_value_type_factory.rb

Overview

Requiring 'renum' mixes the Renum module into both the main Object and Module, so it can be called from anywhere that you might reasonably define an enumeration with an implicit receiver.

Defined Under Namespace

Modules: EnumeratedValueTypeFactory Classes: EnumeratedValue, IndexSerializer, NameSerializer

Instance Method Summary (collapse)

Instance Method Details

- (Object) enum(type_name, values = :defined_in_block, &block)

Declares an enumerated type. If called inside a module, the enumerated type class will be nested inside that module.

Parameters:

  • type_name (Symbol)

    The name of the EnumeratedType class to create

  • values (optional, Array<Symbol, String>) (defaults to: :defined_in_block)

    the names of the values in order, can be omitted if you'll specify them via method calls in a block

  • block

    can be used to specify values with method calls, instance methods



17
18
19
20
# File 'lib/renum.rb', line 17

def enum type_name, values = :defined_in_block, &block
  nest = self.is_a?(Module) ? self : Object
  EnumeratedValueTypeFactory.create(nest, type_name, values, &block)
end