Class: Dry::Struct::Constructor

Inherits:
Object
  • Object
show all
Includes:
Types::Type
Defined in:
lib/dry/struct/constructor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options = {}, &block) ⇒ Constructor

Returns a new instance of Constructor.

Parameters:

  • type (Struct)
  • options (Hash) (defaults to: {})
  • block (#call, nil)


16
17
18
19
# File 'lib/dry/struct/constructor.rb', line 16

def initialize(type, options = {}, &block)
  @type = type
  @fn = options.fetch(:fn, block)
end

Instance Attribute Details

#fn#call (readonly)

Returns:



8
9
10
# File 'lib/dry/struct/constructor.rb', line 8

def fn
  @fn
end

#type#call (readonly)

Returns:



11
12
13
# File 'lib/dry/struct/constructor.rb', line 11

def type
  @type
end

Instance Method Details

#call(input) ⇒ Object Also known as: []

Parameters:

  • input (Object)

Returns:

  • (Object)


23
24
25
# File 'lib/dry/struct/constructor.rb', line 23

def call(input)
  type[fn[input]]
end