Module: Type::Definition::ClassMethods

Defined in:
lib/type/definition.rb

Instance Method Summary collapse

Instance Method Details

#generate(name, &block) ⇒ Type::Definition #generate(name) ⇒ Type::Definition::Proxy

Returns @example ~~~ ruby

Type::scalar(:Int32).from(:Integer) do
  int32_range = (-1 << 31) ... (1 << 31)
  validate do |input|
    int32_range.include?(input)
  end
end

~~~.

Overloads:

  • #generate(name, &block) ⇒ Type::Definition

    The block is called in the context of the definition, and is expected to call one of #validate or #cast with appropriate blocks. ~~~ ruby

    Type::scalar(:Integer) do
      validate do |input|
        input.kind_of?(::Integer)
      end
      cast do |input|
        Kernel::Integer(input)
      end
    end
    

    ~~~



54
55
56
57
# File 'lib/type/definition.rb', line 54

def generate(name = nil, &block)
  return new(name, &block) if block_given?
  Proxy.new(name, self)
end