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

==   and   assert_int!   comma   concat   div   eq   inspect   minus   neq   new   or   perform   plus   to_bool   to_i   unary_div   unary_minus   unary_not  

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

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:     end

Public Instance methods

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 164
164:     def ==(other)
165:       eq(other).to_bool
166:     end

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 40
40:     def and(other)
41:       to_bool ? other : self
42:     end

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

[Source]

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

[Source]

     # 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

[Source]

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

[Source]

     # 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

[Source]

    # 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

@return [String] A readable representation of the literal

[Source]

     # File lib/sass/script/literal.rb, line 151
151:     def inspect
152:       value.inspect
153:     end

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

[Source]

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

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 50
50:     def or(other)
51:       to_bool ? self : other
52:     end

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

[Source]

     # 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)

[Source]

     # 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

[Source]

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

[Source]

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

[Source]

     # 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

[Source]

    # File lib/sass/script/literal.rb, line 83
83:     def unary_not
84:       Sass::Script::Bool.new(!to_bool)
85:     end

[Validate]