Class: StrongJSON::Type::Optional

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

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Optional

Returns a new instance of Optional.



38
39
40
# File 'lib/strong_json/type.rb', line 38

def initialize(type)
  @type = type
end

Instance Method Details

#coerce(value, path: []) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/strong_json/type.rb', line 42

def coerce(value, path: [])
  if value != nil
    @type.coerce(value, path: path)
  else
    nil
  end
end

#to_sObject



50
51
52
# File 'lib/strong_json/type.rb', line 50

def to_s
  "optinal(#{@type})"
end