class Sass::Script::Tree::UnaryOperation

A SassScript parse node representing a unary operation, such as `-$b` or `not true`.

Currently only `-`, `/`, and `not` are unary operators.

Attributes

operand[R]

@return [Script::Node] The parse-tree node for the object of the operator

operator[R]

@return [Symbol] The operation to perform

Public Class Methods

new(operand, operator) click to toggle source

@param operand [Script::Node] See {#operand} @param operator [Symbol] See {#operator}

Calls superclass method
# File lib/sass/script/tree/unary_operation.rb, line 15
def initialize(operand, operator)
  @operand = operand
  @operator = operator
  super()
end

Public Instance Methods

children() click to toggle source

Returns the operand of the operation.

@return [Array<Node>] @see Sass::Script::Tree::Node#children

# File lib/sass/script/tree/unary_operation.rb, line 42
def children
  [@operand]
end
deep_copy() click to toggle source

@see Sass::Script::Tree::Node#deep_copy

# File lib/sass/script/tree/unary_operation.rb, line 47
def deep_copy
  node = dup
  node.instance_variable_set('@operand', @operand.deep_copy)
  node
end
inspect() click to toggle source

@return [String] A human-readable s-expression representation of the operation

# File lib/sass/script/tree/unary_operation.rb, line 22
def inspect
  "(#{@operator.inspect} #{@operand.inspect})"
end
to_sass(opts = {}) click to toggle source

@see Sass::Script::Tree::Node#to_sass

# File lib/sass/script/tree/unary_operation.rb, line 27
def to_sass(opts = {})
  operand = @operand.to_sass(opts)
  if @operand.is_a?(Operation) ||
      (@operator == :minus &&
       (operand =~ Sass::SCSS::RX::IDENT) == 0)
    operand = "(#{@operand.to_sass(opts)})"
  end
  op = Sass::Script::Lexer::OPERATORS_REVERSE[@operator]
  op + (op =~ /[a-z]/ ? " " : "") + operand
end

Protected Instance Methods

_perform(environment) click to toggle source

Evaluates the operation.

@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Sass::Script::Value] The SassScript object that is the value of the operation @raise [Sass::SyntaxError] if the operation is undefined for the operand

# File lib/sass/script/tree/unary_operation.rb, line 60
def _perform(environment)
  operator = "unary_#{@operator}"
  value = @operand.perform(environment)
  value.send(operator)
rescue NoMethodError => e
  raise e unless e.name.to_s == operator.to_s
  raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{value}\".")
end