Class: ObjectForge::Molds::ArrayMold

Inherits:
Object
  • Object
show all
Defined in:
lib/object_forge/molds/array_mold.rb

Overview

Mold for constructing Arrays.

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

#call(forge_target:, attributes:, **_) ⇒ Array

Build a new array from attributes’ values.

If forge_target is Array, result is built directly by calling attributes.values. If it is a different class, its .new method is called with the values array.

Parameters:

  • forge_target (Class)

    Array or a subclass of Array

  • attributes (Hash{Symbol => Any})

Returns:

  • (Array)

See Also:

  • Array.new

Since:

  • 0.5.0



20
21
22
23
24
# File 'lib/object_forge/molds/array_mold.rb', line 20

def call(forge_target:, attributes:, **_)
  return attributes.values if Array == forge_target # rubocop:disable Style/YodaCondition

  forge_target.new(attributes.values)
end