Class Sass::Script::Operation
In: lib/sass/script/operation.rb
Parent: Node

A SassScript parse node representing a binary operation, such as `!a + !b` or `"foo" + 1`.

Methods

inspect   new   perform  

Public Class methods

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

  for the right-hand side of the operator

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

  for the left-hand side of the operator

@param operator [Symbol] The operator to perform.

  This should be one of the binary operator names in {Lexer::OPERATORS}

[Source]

    # File lib/sass/script/operation.rb, line 18
18:     def initialize(operand1, operand2, operator)
19:       @operand1 = operand1
20:       @operand2 = operand2
21:       @operator = operator
22:     end

Public Instance methods

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

[Source]

    # File lib/sass/script/operation.rb, line 25
25:     def inspect
26:       "(#{@operator.inspect} #{@operand1.inspect} #{@operand2.inspect})"
27:     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 operands

[Source]

    # File lib/sass/script/operation.rb, line 34
34:     def perform(environment)
35:       literal1 = @operand1.perform(environment)
36:       literal2 = @operand2.perform(environment)
37:       begin
38:         literal1.send(@operator, literal2)
39:       rescue NoMethodError => e
40:         raise e unless e.name.to_s == @operator.to_s
41:         raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\".")
42:       end
43:     end

[Validate]