Class Sass::Script::UnaryOperation
In: lib/sass/script/unary_operation.rb
Parent: Node

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

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

Methods

_perform   children   inspect   new   to_sass  

Public Class methods

@param operand [Script::Node] The parse-tree node

  for the object of the operator

@param operator [Symbol] The operator to perform

[Source]

    # File lib/sass/script/unary_operation.rb, line 10
10:     def initialize(operand, operator)
11:       @operand = operand
12:       @operator = operator
13:       super()
14:     end

Public Instance methods

Returns the operand of the operation.

@return [Array<Node>] @see Node#children

[Source]

    # File lib/sass/script/unary_operation.rb, line 37
37:     def children
38:       [@operand]
39:     end

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

[Source]

    # File lib/sass/script/unary_operation.rb, line 17
17:     def inspect
18:       "(#{@operator.inspect} #{@operand.inspect})"
19:     end

@see Node#to_sass

[Source]

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

Protected Instance methods

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

[Source]

    # File lib/sass/script/unary_operation.rb, line 48
48:     def _perform(environment)
49:       operator = "unary_#{@operator}"
50:       literal = @operand.perform(environment)
51:       literal.send(operator)
52:     rescue NoMethodError => e
53:       raise e unless e.name.to_s == operator.to_s
54:       raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{literal}\".")
55:     end

[Validate]