Class: StrongJSON::Type::Optional

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

Instance Method Summary collapse

Methods included from Match

#===, #=~

Constructor Details

#initialize(type) ⇒ Optional

Returns a new instance of Optional.



70
71
72
# File 'lib/strong_json/type.rb', line 70

def initialize(type)
  @type = type
end

Instance Method Details

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



74
75
76
77
78
79
80
# File 'lib/strong_json/type.rb', line 74

def coerce(value, path: [])
  unless value == nil || NONE.equal?(value)
    @type.coerce(value, path: path)
  else
    nil
  end
end

#to_sObject



82
83
84
# File 'lib/strong_json/type.rb', line 82

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