Class: ObjectForge::Molds::MoldMold

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

Overview

Special “mold” that returns appropriate mold for the given forged object. Probably not the best fit though.

Currently provides specific recognition for:

Other objects just get SingleArgumentMold.

Since:

  • 0.2.0

Instance Method Summary collapse

Instance Method Details

#call(forged:, **_) ⇒ #call

Get maybe appropriate mold for the given forged object.

Parameters:

  • forged (Class, Any)

Returns:

  • (#call)

    an instance of a mold

Since:

  • 0.2.0



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/object_forge/molds/mold_mold.rb', line 21

def call(forged:, **_)
  # rubocop:disable Style/YodaCondition
  if ::Class === forged
    if ::Struct > forged
      StructMold.new
    elsif defined?(::Data) && ::Data > forged
      KeywordsMold.new
    elsif ::Hash >= forged
      HashMold.new
    else
      SingleArgumentMold.new
    end
  else
    SingleArgumentMold.new
  end
  # rubocop:enable Style/YodaCondition
end