Class: Strict::Interfaces::Coercer

Inherits:
Object
  • Object
show all
Defined in:
lib/strict/interfaces/coercer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface_class) ⇒ Coercer

Returns a new instance of Coercer.



8
9
10
# File 'lib/strict/interfaces/coercer.rb', line 8

def initialize(interface_class)
  @interface_class = interface_class
end

Instance Attribute Details

#interface_classObject (readonly)

Returns the value of attribute interface_class.



6
7
8
# File 'lib/strict/interfaces/coercer.rb', line 6

def interface_class
  @interface_class
end

Instance Method Details

#call(value) ⇒ Object



12
13
14
15
16
# File 'lib/strict/interfaces/coercer.rb', line 12

def call(value)
  return value if value.nil? || value.instance_of?(interface_class)

  interface_class.new(value)
end