Class: Diva::Type::OptionalType

Inherits:
MetaType
  • Object
show all
Defined in:
lib/diva/type.rb

Instance Attribute Summary

Attributes inherited from MetaType

#name

Instance Method Summary collapse

Methods inherited from MetaType

#inspect

Constructor Details

#initialize(type) ⇒ OptionalType

Returns a new instance of OptionalType.



174
175
176
177
# File 'lib/diva/type.rb', line 174

def initialize(type)
  super("optional_#{type.name}")
  @type = type
end

Instance Method Details

#cast(value) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/diva/type.rb', line 179

def cast(value)
  if value.nil?
    value
  else
    @type.cast(value)
  end
end

#to_sObject



187
188
189
# File 'lib/diva/type.rb', line 187

def to_s
  "#{type.to_s}|nil"
end