Class: Sass::Script::UnaryOperation
- Defined in:
- lib/sass/script/unary_operation.rb
Overview
A SassScript parse node representing a unary operation, such as ‘-!b` or `not true`.
Currently only ‘-`, `/`, and `not` are unary operators.
Instance Method Summary collapse
-
#initialize(operand, operator) ⇒ UnaryOperation
constructor
A new instance of UnaryOperation.
-
#inspect ⇒ String
A human-readable s-expression representation of the operation.
-
#perform(environment) ⇒ Literal
Evaluates the operation.
Constructor Details
#initialize(operand, operator) ⇒ UnaryOperation
Returns a new instance of UnaryOperation.
10 11 12 13 |
# File 'lib/sass/script/unary_operation.rb', line 10 def initialize(operand, operator) @operand = operand @operator = operator end |
Instance Method Details
#inspect ⇒ String
Returns A human-readable s-expression representation of the operation.
16 17 18 |
# File 'lib/sass/script/unary_operation.rb', line 16 def inspect "(#{@operator.inspect} #{@operand.inspect})" end |
#perform(environment) ⇒ Literal
Evaluates the operation.
25 26 27 28 29 30 31 32 |
# File 'lib/sass/script/unary_operation.rb', line 25 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 |