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.
77 78 79 |
# File 'lib/mighty_json/type.rb', line 77 def initialize(type) @type = type end |
Instance Method Details
#compile(var:, path:) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/mighty_json/type.rb', line 81 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
92 93 94 |
# File 'lib/mighty_json/type.rb', line 92 def to_s "optinal(#{@type})" end |