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.

### Methods

== _perform and assert_int! children comma concat div eq inspect minus neq new options or plus single_eq to_bool to_i to_s to_sass unary_div unary_minus unary_not unary_plus

### Attributes

value | [R] | Returns the Ruby value of the literal. The type of this value varies based on the subclass. @return [Object]

### Public Class methods

new(value = nil)

Creates a new literal.

@param value [Object] The object for \{value}

[Source]

        # File lib/sass/script/literal.rb, line 22
    22:     def initialize(value = nil)
    23:       @value = value
    24:       super()
    25:     end

### Public Instance methods

==(other)

Compares this object with another.

@param other [Object] The object to compare with @return [Boolean] Whether or not this literal is equivalent to `other`

[Source]

         # File lib/sass/script/literal.rb, line 205
    205:     def ==(other)
    206:       eq(other).to_bool
    207:     end

and(other)

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

[Source]

        # File lib/sass/script/literal.rb, line 59
    59:     def and(other)
    60:       to_bool ? other : self
    61:     end

assert_int!()

@raise [Sass::SyntaxError] if this literal isn‘t an integer

[Source]

         # File lib/sass/script/literal.rb, line 216
    216:     def assert_int!; to_i; end

children()

Returns an empty array.

@return [Array<Node>] empty @see Node#children

[Source]

        # File lib/sass/script/literal.rb, line 31
    31:     def children
    32:       []
    33:     end

comma(other)

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 `", "`

[Source]

         # File lib/sass/script/literal.rb, line 120
    120:     def comma(other)
    121:       Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
    122:     end

concat(other)

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

[Source]

         # File lib/sass/script/literal.rb, line 111
    111:     def concat(other)
    112:       Sass::Script::String.new("#{self.to_s} #{other.to_s}")
    113:     end

div(other)

The SassScript `/` operation.

@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals

      separated by `"/"`

[Source]

         # File lib/sass/script/literal.rb, line 160
    160:     def div(other)
    161:       Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
    162:     end

eq(other)

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

[Source]

        # File lib/sass/script/literal.rb, line 80
    80:     def eq(other)
    81:       Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
    82:     end

inspect()

@return [String] A readable representation of the literal

[Source]

         # File lib/sass/script/literal.rb, line 192
    192:     def inspect
    193:       value.inspect
    194:     end

minus(other)

The SassScript `-` operation.

@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals

      separated by `"-"`

[Source]

         # File lib/sass/script/literal.rb, line 151
    151:     def minus(other)
    152:       Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
    153:     end

neq(other)

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

[Source]

        # File lib/sass/script/literal.rb, line 91
    91:     def neq(other)
    92:       Sass::Script::Bool.new(!eq(other).to_bool)
    93:     end

options()

Returns the options hash for this node.

@return [{Symbol => Object}] @raise [Sass::SyntaxError] if the options hash hasn‘t been set.

      This should only happen when the literal was created
      outside of the parser and \{#to\_s} was called on it

[Source]

        # File lib/sass/script/literal.rb, line 41
    41:     def options
    42:       opts = super
    43:       return opts if opts
    44:       raise Sass::SyntaxError.new("The #options attribute is not set on this \#{self.class}.\n  This error is probably occurring because #to_s was called\n  on this literal within a custom Sass function without first\n  setting the #option attribute.\n")
    45:     end

or(other)

The SassScript `or` operation.

@param other [Literal] The right-hand side of the operator @return [Literal] The result of the logical or:

      this literal if it isn't a false {Bool},
      and `other` otherwise

[Source]

        # File lib/sass/script/literal.rb, line 69
    69:     def or(other)
    70:       to_bool ? self : other
    71:     end

plus(other)

The SassScript `+` operation.

@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals

      without any separation

[Source]

         # File lib/sass/script/literal.rb, line 139
    139:     def plus(other)
    140:       if other.is_a?(Sass::Script::String)
    141:         return Sass::Script::String.new(self.to_s + other.value, other.type)
    142:       end
    143:       Sass::Script::String.new(self.to_s + other.to_s)
    144:     end

single_eq(other)

The SassScript `=` operation (used for proprietary MS syntax like `alpha(opacity=20)`).

@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals

      separated by `"="`

[Source]

         # File lib/sass/script/literal.rb, line 130
    130:     def single_eq(other)
    131:       Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
    132:     end

to_bool()

@return [Boolean] `true` (the Ruby boolean value)

[Source]

         # File lib/sass/script/literal.rb, line 197
    197:     def to_bool
    198:       true
    199:     end

to_i()

@return [Fixnum] The integer value of this literal @raise [Sass::SyntaxError] if this literal isn‘t an integer

[Source]

         # File lib/sass/script/literal.rb, line 211
    211:     def to_i
    212:       raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
    213:     end

to_s(opts = {})

Returns the string representation of this literal as it would be output to the CSS document.

@return [String]

[Source]

         # File lib/sass/script/literal.rb, line 222
    222:     def to_s(opts = {})
    223:       raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
    224:     end

to_sass(opts = {})

Alias for to_s

unary_div()

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 `"/"`

[Source]

         # File lib/sass/script/literal.rb, line 187
    187:     def unary_div
    188:       Sass::Script::String.new("/#{self.to_s}")
    189:     end

unary_minus()

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 `"-"`

[Source]

         # File lib/sass/script/literal.rb, line 178
    178:     def unary_minus
    179:       Sass::Script::String.new("-#{self.to_s}")
    180:     end

unary_not()

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

[Source]

         # File lib/sass/script/literal.rb, line 102
    102:     def unary_not
    103:       Sass::Script::Bool.new(!to_bool)
    104:     end

unary_plus()

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 `"+"`

[Source]

         # File lib/sass/script/literal.rb, line 169
    169:     def unary_plus
    170:       Sass::Script::String.new("+#{self.to_s}")
    171:     end

### Protected Instance methods

_perform(environment)

Evaluates the literal.

@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Literal] This literal

[Source]

         # File lib/sass/script/literal.rb, line 233
    233:     def _perform(environment)
    234:       self
    235:     end

[Validate]