Module: Acclaim::Option::Type

Extended by:
Enumerable
Defined in:
lib/acclaim/option/type.rb,
lib/acclaim/option/type/uri.rb,
lib/acclaim/option/type/date.rb,
lib/acclaim/option/type/time.rb,
lib/acclaim/option/type/float.rb,
lib/acclaim/option/type/string.rb,
lib/acclaim/option/type/symbol.rb,
lib/acclaim/option/type/complex.rb,
lib/acclaim/option/type/integer.rb,
lib/acclaim/option/type/pathname.rb,
lib/acclaim/option/type/rational.rb,
lib/acclaim/option/type/date_time.rb,
lib/acclaim/option/type/big_decimal.rb

Overview

Associates a class with a handler block.

Author:

  • Matheus Afonso Martins Moreira

Since:

  • 0.0.4

Defined Under Namespace

Modules: BigDecimal, Complex, Date, DateTime, Float, Integer, Pathname, Rational, String, Symbol, Time, URI

Class Method Summary collapse

Class Method Details

.allArray<Class, Module> Also known as: registered

Returns all registered classes.

Returns:

  • (Array<Class, Module>)

    registered types

Since:

  • 0.0.4



29
30
31
# File 'lib/acclaim/option/type.rb', line 29

def all
  table.keys
end

.each {|type, handler| ... } ⇒ Object

Yields class, proc pairs if a block was given. Returns an enumerator otherwise.

Yield Parameters:

  • type (Class, Module)

    the class or module

  • handler (Proc)

    the type handler

Since:

  • 0.0.4



19
20
21
# File 'lib/acclaim/option/type.rb', line 19

def each(&block)
  table.each &block
end

.handler_for(type) ⇒ Object Also known as: []

Returns the handler for the given class.

Parameters:

  • type (Class, Module)

    the handler associated with the given type

Since:

  • 0.0.4



51
52
53
54
55
# File 'lib/acclaim/option/type.rb', line 51

def handler_for(type)
  table.fetch type do
    raise "#{type} does not have an associated handler"
  end
end

.register(*types, &block) {|string| ... } ⇒ Object Also known as: add_handler_for, accept

Registers a handler for a class.

Parameters:

  • types (Class, Module)

    the types to associate with the handler

  • block (Proc)

    the type handler

Yield Parameters:

  • string (String)

    the command line argument

Yield Returns:

  • (Class, Module)

    new object of the handled type

Since:

  • 0.0.4



41
42
43
# File 'lib/acclaim/option/type.rb', line 41

def register(*types, &block)
  types.each { |type| table[type] = block }
end