Class: StrongJSON::Type::Optional
- Inherits:
-
Object
- Object
- StrongJSON::Type::Optional
- 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
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_s ⇒ Object
50 51 52 |
# File 'lib/strong_json/type.rb', line 50 def to_s "optinal(#{@type})" end |