Sha256: ad950777b62c35294e21fec0fe72ace1afb38e24e1d1ddce9fd79415a3d1dcd0

Contents?: true

Size: 816 Bytes

Versions: 5

Compression:

Stored size: 816 Bytes

Contents

module Dentaku
  module AST
    class Negation < Arithmetic
      def initialize(node)
        @node = node

        unless valid_node?(node)
          raise NodeError.new(:numeric, left.type, :left),
                "#{self.class} requires numeric operands"
        end
      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

5 entries across 5 versions & 1 rubygems

Version Path
dentaku-3.3.1 lib/dentaku/ast/negation.rb
dentaku-3.3.0 lib/dentaku/ast/negation.rb
dentaku-3.2.1 lib/dentaku/ast/negation.rb
dentaku-3.2.0 lib/dentaku/ast/negation.rb
dentaku-3.1.0 lib/dentaku/ast/negation.rb