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.

Since:

  • 0.0.1

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.allObject Also known as: registered

Returns all registered classes.

Since:

  • 0.0.1



21
22
23
# File 'lib/acclaim/option/type.rb', line 21

def all
  table.keys
end

.each(&block) ⇒ Object

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

Since:

  • 0.0.1



13
14
15
# File 'lib/acclaim/option/type.rb', line 13

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

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

Returns the handler for the given class.

Since:

  • 0.0.1



31
32
33
34
35
# File 'lib/acclaim/option/type.rb', line 31

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

.register(*klasses, &block) ⇒ Object Also known as: add_handler_for, accept

Registers a handler for a class.

Since:

  • 0.0.1



26
27
28
# File 'lib/acclaim/option/type.rb', line 26

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