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.
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_s ⇒ Object
82 83 84 |
# File 'lib/strong_json/type.rb', line 82 def to_s "optinal(#{@type})" end |