Sha256: eeae02b383f0219d1639cb5ffb5ed7bbe969a382d0a877a91f2723284e7635f6

Contents?: true

Size: 735 Bytes

Versions: 1

Compression:

Stored size: 735 Bytes

Contents

module Dentaku
  module AST
    class Negation < Arithmetic
      def initialize(node)
        @node = node
        fail ParseError, "Negation requires numeric operand" unless valid_node?(node)
      end

      def operator
        :*
      end

      def value(context={})
        cast(@node.value(context)) * -1
      end

      def type
        :numeric
      end

      def self.arity
        1
      end

      def self.right_associative?
        true
      end

      def self.precedence
        40
      end

      def dependencies(context={})
        @node.dependencies(context)
      end

      private

      def valid_node?(node)
        node && (node.dependencies.any? || node.type == :numeric)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dentaku-2.0.11 lib/dentaku/ast/negation.rb