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