Method: Sass::Script::Operation#_perform

Defined in:
lib/sass/script/operation.rb

#_perform(environment) ⇒ Literal (protected)

Evaluates the operation.

Parameters:

  • environment (Sass::Environment)

    The environment in which to evaluate the SassScript

Returns:

  • (Literal)

    The SassScript object that is the value of the operation

Raises:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sass/script/operation.rb', line 72

def _perform(environment)
  literal1 = @operand1.perform(environment)

  # Special-case :and and :or to support short-circuiting.
  if @operator == :and
    return literal1.to_bool ? @operand2.perform(environment) : literal1
  elsif @operator == :or
    return literal1.to_bool ? literal1 : @operand2.perform(environment)
  end

  literal2 = @operand2.perform(environment)

  if (literal1.is_a?(Null) || literal2.is_a?(Null)) && @operator != :eq && @operator != :neq
    raise Sass::SyntaxError.new("Invalid null operation: \"#{literal1.inspect} #{@operator} #{literal2.inspect}\".")
  end

  begin
    opts(literal1.send(@operator, literal2))
  rescue NoMethodError => e
    raise e unless e.name.to_s == @operator.to_s
    raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\".")
  end
end