class MightyJSON::Type::Optional

Public Class Methods

new(type) click to toggle source
# File lib/mighty_json/type.rb, line 77
def initialize(type)
  @type = type
end

Public Instance Methods

compile(var:, path:) click to toggle source
# File lib/mighty_json/type.rb, line 81
      def compile(var:, path:)
        v = var.cur
        <<~END
          if #{v}.nil? || none.equal?(#{v})
            nil
          else
            #{@type.compile(var: var, path: path)}
          end
        END
      end
to_s() click to toggle source
# File lib/mighty_json/type.rb, line 92
def to_s
  "optinal(#{@type})"
end