Class: MightyJSON::Type::Optional
- Inherits:
-
Object
- Object
- MightyJSON::Type::Optional
- Defined in:
- lib/mighty_json/type.rb
Instance Method Summary collapse
- #compile(var:, 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.
63 64 65 |
# File 'lib/mighty_json/type.rb', line 63 def initialize(type) @type = type end |
Instance Method Details
#compile(var:, path:) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mighty_json/type.rb', line 67 def compile(var:, path:) v = var.cur " if \#{v}.nil? || NONE.equal?(\#{v})\n nil\n else\n \#{@type.compile(var: var, path: path)}\n end\n END\nend\n" |
#to_s ⇒ Object
78 79 80 |
# File 'lib/mighty_json/type.rb', line 78 def to_s "optinal(#{@type})" end |