Sha256: ec9f37a157729b316c0ba083d5c1015fce98d94d435755ebad638a5f1af15be4

Contents?: true

Size: 1.36 KB

Versions: 31

Compression:

Stored size: 1.36 KB

Contents

module Sass::Script
  # A SassScript parse node representing a unary operation,
  # such as `-!b` or `not true`.
  #
  # Currently only `-`, `/`, and `not` are unary operators.
  class UnaryOperation < Node
    # @param operand [Script::Node] The parse-tree node
    #   for the object of the operator
    # @param operator [Symbol] The operator to perform
    def initialize(operand, operator)
      @operand = operand
      @operator = operator
    end

    # @return [String] A human-readable s-expression representation of the operation
    def inspect
      "(#{@operator.inspect} #{@operand.inspect})"
    end

    # Evaluates the operation.
    #
    # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
    # @return [Literal] The SassScript object that is the value of the operation
    # @raise [Sass::SyntaxError] if the operation is undefined for the operand
    def perform(environment)
      operator = "unary_#{@operator}"
      literal = @operand.perform(environment)
      literal.send(operator)
    rescue NoMethodError => e
      raise e unless e.name.to_s == operator.to_s
      raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{literal}\".")
    end

    # Returns the operand of the operation.
    #
    # @return [Array<Node>]
    # @see Node#children
    def children
      [@operand]
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
haml-edge-2.3.179 lib/sass/script/unary_operation.rb
haml-edge-2.3.178 lib/sass/script/unary_operation.rb
haml-edge-2.3.177 lib/sass/script/unary_operation.rb
haml-edge-2.3.176 lib/sass/script/unary_operation.rb
haml-edge-2.3.175 lib/sass/script/unary_operation.rb
haml-edge-2.3.174 lib/sass/script/unary_operation.rb
haml-edge-2.3.173 lib/sass/script/unary_operation.rb
haml-edge-2.3.172 lib/sass/script/unary_operation.rb
haml-edge-2.3.171 lib/sass/script/unary_operation.rb
haml-edge-2.3.170 lib/sass/script/unary_operation.rb
haml-edge-2.3.169 lib/sass/script/unary_operation.rb
haml-edge-2.3.168 lib/sass/script/unary_operation.rb
haml-edge-2.3.167 lib/sass/script/unary_operation.rb
haml-edge-2.3.166 lib/sass/script/unary_operation.rb
haml-edge-2.3.165 lib/sass/script/unary_operation.rb
haml-edge-2.3.164 lib/sass/script/unary_operation.rb
haml-edge-2.3.163 lib/sass/script/unary_operation.rb
haml-edge-2.3.162 lib/sass/script/unary_operation.rb
haml-edge-2.3.161 lib/sass/script/unary_operation.rb
haml-edge-2.3.160 lib/sass/script/unary_operation.rb