Sha256: 95fbbc37e75a24db15da76851d9a39dfaf88cf9a1f707db453c379684dac6c7d

Contents?: true

Size: 1.21 KB

Versions: 175

Compression:

Stored size: 1.21 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
  end
end

Version data entries

175 entries across 174 versions & 7 rubygems

Version Path
radiantcms-couchrest_model-0.1.4 vendor/plugins/haml/lib/sass/script/unary_operation.rb
radiant-0.9.1 vendor/plugins/haml/lib/sass/script/unary_operation.rb
haml-2.2.24 lib/sass/script/unary_operation.rb
radiant-0.9.0.rc2 vendor/plugins/haml/lib/sass/script/unary_operation.rb
haml-2.2.23 lib/sass/script/unary_operation.rb
haml-2.2.22 lib/sass/script/unary_operation.rb
haml-2.2.21 lib/sass/script/unary_operation.rb
drnic-haml-2.3.1 lib/sass/script/unary_operation.rb
haml-2.2.20 lib/sass/script/unary_operation.rb
haml-2.2.19 lib/sass/script/unary_operation.rb
haml-2.2.18 lib/sass/script/unary_operation.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/haml-2.2.17/lib/sass/script/unary_operation.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/haml-2.2.17/lib/sass/script/unary_operation.rb
haml-2.2.17 lib/sass/script/unary_operation.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/haml-2.2.16/lib/sass/script/unary_operation.rb
simple-templater-0.0.1.4 gems/gems/haml-2.2.16/lib/sass/script/unary_operation.rb
haml-2.2.16 lib/sass/script/unary_operation.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/unary_operation.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/unary_operation.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/unary_operation.rb