Sha256: 94b31636917d8b39fb41e815d0ae746362dfc85415c7869aa16d662af89f84b1

Contents?: true

Size: 488 Bytes

Versions: 1

Compression:

Stored size: 488 Bytes

Contents

module FilterParam
  module AST
    class Literal < Node
      attr_accessor :value

      def initialize(value = nil)
        @value = value
      end

      def type_cast(type)
        return self if type.blank?

        cast_method = "to_#{type}"
        return send(cast_method) if respond_to?(cast_method, true)

        raise InvalidLiteral.new("Cannot cast '#{value}' to #{type}")
      end

      private

      def visit_method
        :visit_literal
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
filter_param-0.1.2 lib/filter_param/ast/literal.rb