Class: Sass::Script::Tree::UnaryOperation
- Inherits:
- Node
- Object
- Node
- Sass::Script::Tree::UnaryOperation
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/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 Attribute Summary (collapse)
- - (Script::Node) operand readonly
The parse-tree node for the object of the operator.
- - (Symbol) operator readonly
The operation to perform.
Attributes inherited from Node
#css_variable_warning, #filename, #line, #options, #source_range
Instance Method Summary (collapse)
- - (Sass::Script::Value) _perform(environment) protected
Evaluates the operation.
- - (Array<Node>) children
Returns the operand of the operation.
- - deep_copy
- - (UnaryOperation) initialize(operand, operator) constructor
A new instance of UnaryOperation.
- - (String) inspect
A human-readable s-expression representation of the operation.
- - to_sass(opts = {})
Methods inherited from Node
#dasherize, #force_division!, #opts, #perform
Constructor Details
- (UnaryOperation) initialize(operand, operator)
Returns a new instance of UnaryOperation
15 16 17 18 19 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/unary_operation.rb', line 15
def initialize(operand, operator)
@operand = operand
@operator = operator
super()
end |
Instance Attribute Details
- (Script::Node) operand (readonly)
Returns The parse-tree node for the object of the operator
11 12 13 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/unary_operation.rb', line 11
def operand
@operand
end |
- (Symbol) operator (readonly)
Returns The operation to perform
8 9 10 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/unary_operation.rb', line 8
def operator
@operator
end |
Instance Method Details
- (Sass::Script::Value) _perform(environment) (protected)
Evaluates the operation.
60 61 62 63 64 65 66 67 | # File '/Users/ceppstei/Projects/sass-lang/.sass/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 |
- (Array<Node>) children
Returns the operand of the operation.
42 43 44 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/unary_operation.rb', line 42
def children
[@operand]
end |
- deep_copy
47 48 49 50 51 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/unary_operation.rb', line 47
def deep_copy
node = dup
node.instance_variable_set('@operand', @operand.deep_copy)
node
end |
- (String) inspect
Returns A human-readable s-expression representation of the operation
22 23 24 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/unary_operation.rb', line 22
def inspect
"(#{@operator.inspect} #{@operand.inspect})"
end |
- to_sass(opts = {})
27 28 29 30 31 32 33 34 35 36 | # File '/Users/ceppstei/Projects/sass-lang/.sass/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 |