Class | Sass::Script::Literal |
In: |
lib/sass/script/literal.rb
|
Parent: | Node |
The abstract superclass for SassScript objects.
Many of these methods, especially the ones that correspond to SassScript operations, are designed to be overridden by subclasses which may change the semantics somewhat. The operations listed here are just the defaults.
value | [R] |
Returns the Ruby value of the literal. The type of this value varies based
on the subclass.
@return [Object] |
The SassScript `and` operation.
@param other [Literal] The right-hand side of the operator @return [Literal] The result of a logical and:
`other` if this literal isn't a false {Bool}, and this literal otherwise
# File lib/sass/script/literal.rb, line 40 40: def and(other) 41: to_bool ? other : self 42: end
@raise [Sass::SyntaxError] if this literal isn‘t an integer
# File lib/sass/script/literal.rb, line 175 175: def assert_int!; to_i; end
The SassScript `,` operation (e.g. `!a, !b`, `"foo", "bar"`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by `", "`
# File lib/sass/script/literal.rb, line 101 101: def comma(other) 102: Sass::Script::String.new("#{self.to_s}, #{other.to_s}") 103: end
The SassScript default operation (e.g. `!a !b`, `"foo" "bar"`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by a space
# File lib/sass/script/literal.rb, line 92 92: def concat(other) 93: Sass::Script::String.new("#{self.to_s} #{other.to_s}") 94: end
The SassScript `/` operation.
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by `"/"`
# File lib/sass/script/literal.rb, line 128 128: def div(other) 129: Sass::Script::String.new("#{self.to_s}/#{other.to_s}") 130: end
The SassScript `==` operation. **Note that this returns a {Sass::Script::Bool} object, not a Ruby boolean**.
@param other [Literal] The right-hand side of the operator @return [Bool] True if this literal is the same as the other,
false otherwise
# File lib/sass/script/literal.rb, line 61 61: def eq(other) 62: Sass::Script::Bool.new(self.class == other.class && self.value == other.value) 63: end
The SassScript `-` operation.
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by `"-"`
# File lib/sass/script/literal.rb, line 119 119: def minus(other) 120: Sass::Script::String.new("#{self.to_s}-#{other.to_s}") 121: end
The SassScript `!=` operation. **Note that this returns a {Sass::Script::Bool} object, not a Ruby boolean**.
@param other [Literal] The right-hand side of the operator @return [Bool] False if this literal is the same as the other,
true otherwise
# File lib/sass/script/literal.rb, line 72 72: def neq(other) 73: Sass::Script::Bool.new(!eq(other).to_bool) 74: end
Evaluates the literal.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Literal] This literal
# File lib/sass/script/literal.rb, line 30 30: def perform(environment) 31: self 32: end
The SassScript `+` operation.
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
without any separation
# File lib/sass/script/literal.rb, line 110 110: def plus(other) 111: Sass::Script::String.new(self.to_s + other.to_s) 112: end
@return [Boolean] `true` (the Ruby boolean value)
# File lib/sass/script/literal.rb, line 156 156: def to_bool 157: true 158: end
@return [Fixnum] The integer value of this literal @raise [Sass::SyntaxError] if this literal isn‘t an integer
# File lib/sass/script/literal.rb, line 170 170: def to_i 171: raise Sass::SyntaxError.new("#{self.inspect} is not an integer.") 172: end
The SassScript unary `/` operation (e.g. `/!a`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing the literal
preceded by `"/"`
# File lib/sass/script/literal.rb, line 146 146: def unary_div 147: Sass::Script::String.new("/#{self.to_s}") 148: end
The SassScript unary `-` operation (e.g. `-!a`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing the literal
preceded by `"-"`
# File lib/sass/script/literal.rb, line 137 137: def unary_minus 138: Sass::Script::String.new("-#{self.to_s}") 139: end
The SassScript `==` operation. **Note that this returns a {Sass::Script::Bool} object, not a Ruby boolean**.
@param other [Literal] The right-hand side of the operator @return [Bool] True if this literal is the same as the other,
false otherwise
# File lib/sass/script/literal.rb, line 83 83: def unary_not 84: Sass::Script::Bool.new(!to_bool) 85: end