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.



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

def initialize(type)
  @type = type
end

Instance Method Details

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



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

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

#to_sObject



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

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