Class: Definition::Types::Type

Inherits:
Base
  • Object
show all
Defined in:
lib/definition/types/type.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#explain

Constructor Details

#initialize(name, klass, &coerce) ⇒ Type

Returns a new instance of Type.



8
9
10
11
12
# File 'lib/definition/types/type.rb', line 8

def initialize(name, klass, &coerce)
  self.klass = klass
  self.coerce = coerce
  super(name)
end

Instance Method Details

#conform(value) ⇒ Object



14
15
16
17
18
# File 'lib/definition/types/type.rb', line 14

def conform(value)
  value = coerce.call(value) if coerce && !valid?(value)

  try_conform(value)
end