### Home Classes Methods

### In Files

- lib/sass/script/literal.rb

### Parent

Node

### Methods

- ::new
- #==
- #_perform
- #assert_int!
- #children
- #deep_copy
- #div
- #eq
- #inspect
- #minus
- #neq
- #null?
- #options
- #plus
- #single_eq
- #to_a
- #to_bool
- #to_i
- #to_s
- #to_sass
- #unary_div
- #unary_minus
- #unary_not
- #unary_plus

### Class/Module Index

Quicksearch

- Sass
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Generic
- Sass::Exec::Sass
- Sass::Exec::SassConvert
- Sass::Exec::Scss
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::ArgList
- Sass::Script::Bool
- Sass::Script::Color
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Interpolation
- Sass::Script::Lexer
- Sass::Script::List
- Sass::Script::Literal
- Sass::Script::Node
- Sass::Script::Null
- Sass::Script::Number
- Sass::Script::Operation
- Sass::Script::Parser
- Sass::Script::String
- Sass::Script::StringInterpolation
- Sass::Script::UnaryOperation
- Sass::Script::Variable
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Interpolation
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::SelectorPseudoClass
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::Shared
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::MultibyteStringScanner
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object

No matching classes.

# Sass::Script::Literal

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.

### 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) click to toggle source

Creates a new literal.

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

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

### Public Instance Methods

==(other) click to toggle source

Compares this object with another.

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

    # File lib/sass/script/literal.rb, line 174
    def ==(other)
      eq(other).to_bool
    end

assert_int!() click to toggle source

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

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

children() click to toggle source

Returns an empty array.

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

    # File lib/sass/script/literal.rb, line 34
    def children
      []
    end

deep_copy() click to toggle source

@see Node#deep_copy

    # File lib/sass/script/literal.rb, line 39
    def deep_copy
      dup
    end

div(other) click to toggle source

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 129
    def div(other)
      Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
    end

eq(other) click to toggle source

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 67
    def eq(other)
      Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
    end

inspect() click to toggle source

@return [String] A readable representation of the literal

    # File lib/sass/script/literal.rb, line 161
    def inspect
      value.inspect
    end

minus(other) click to toggle source

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 120
    def minus(other)
      Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
    end

neq(other) click to toggle source

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 78
    def neq(other)
      Sass::Script::Bool.new(!eq(other).to_bool)
    end

null?() click to toggle source

Returns whether or not this object is null.

@return [Boolean] `false`

    # File lib/sass/script/literal.rb, line 207
    def null?
      false
    end

options() click to toggle source

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

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

plus(other) click to toggle source

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 108
    def plus(other)
      if other.is_a?(Sass::Script::String)
        return Sass::Script::String.new(self.to_s + other.value, other.type)
      end
      Sass::Script::String.new(self.to_s + other.to_s)
    end

single_eq(other) click to toggle source

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

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

to_a() click to toggle source

Returns the value of this literal as a list. Single literals are considered the same as single-element lists.

@return [Array<Literal>] The of this literal as a list

    # File lib/sass/script/literal.rb, line 191
    def to_a
      [self]
    end

to_bool() click to toggle source

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

    # File lib/sass/script/literal.rb, line 166
    def to_bool
      true
    end

to_i() click to toggle source

@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 180
    def to_i
      raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
    end

to_s(opts = {}) click to toggle source

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

@return [String]

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

Also aliased as: to_sass
to_sass(opts = {}) click to toggle source
Alias for: to_s
unary_div() click to toggle source

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 156
    def unary_div
      Sass::Script::String.new("/#{self.to_s}")
    end

unary_minus() click to toggle source

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 147
    def unary_minus
      Sass::Script::String.new("-#{self.to_s}")
    end

unary_not() click to toggle source

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 89
    def unary_not
      Sass::Script::Bool.new(!to_bool)
    end

unary_plus() click to toggle source

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 138
    def unary_plus
      Sass::Script::String.new("+#{self.to_s}")
    end

### Protected Instance Methods

_perform(environment) click to toggle source

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 217
    def _perform(environment)
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.