Class: Definition::Types::Type
- Defined in:
- lib/definition/types/type.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #conform(value) ⇒ Object
-
#initialize(name, klass, &coerce) ⇒ Type
constructor
A new instance of Type.
Methods inherited from Base
Constructor Details
#initialize(name, klass, &coerce) ⇒ Type
Returns a new instance of Type.
8 9 10 11 12 13 14 |
# File 'lib/definition/types/type.rb', line 8 def initialize(name, klass, &coerce) raise "#{klass.inspect} is not a class" unless klass.is_a?(Class) self.klass = klass self.coerce = coerce super(name, context: { class: klass }) end |
Instance Method Details
#conform(value) ⇒ Object
16 17 18 19 20 |
# File 'lib/definition/types/type.rb', line 16 def conform(value) value = coerce.call(value) if value && coerce && !valid?(value) try_conform(value) end |