Class: StrongJSON::Type::Optional
- Inherits:
-
Object
- Object
- StrongJSON::Type::Optional
- Includes:
- Match
- Defined in:
- lib/strong_json/type.rb
Instance Method Summary collapse
- #coerce(value, path: []) ⇒ Object
-
#initialize(type) ⇒ Optional
constructor
A new instance of Optional.
- #to_s ⇒ Object
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_s ⇒ Object
83 84 85 |
# File 'lib/strong_json/type.rb', line 83 def to_s "optional(#{@type})" end |