Class: Dry::Struct::Constructor

Inherits:
Object
  • Object
show all
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)


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

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

Instance Attribute Details

#fn#call (readonly)

Returns:



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

def fn
  @fn
end

#type#call (readonly)

Returns:



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

def type
  @type
end

Instance Method Details

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

Parameters:

  • input (Object)

Returns:

  • (Object)


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

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