Class: Sass::Script::Variable

Inherits:
Node
  • Object
show all
Defined in:
lib/sass/script/variable.rb

Overview

A SassScript parse node representing a variable.

Instance Attribute Summary collapse

Attributes inherited from Node

#context, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#dasherize, #perform

Constructor Details

#initialize(name) ⇒ Variable

Returns a new instance of Variable.

Parameters:



11
12
13
14
# File 'lib/sass/script/variable.rb', line 11

def initialize(name)
  @name = name
  super()
end

Instance Attribute Details

#nameString (readonly)

The name of the variable.

Returns:



8
9
10
# File 'lib/sass/script/variable.rb', line 8

def name
  @name
end

Instance Method Details

#_perform(environment) ⇒ Literal (protected)

Evaluates the variable.

Parameters:

  • environment (Sass::Environment)

    The environment in which to evaluate the SassScript

Returns:

  • (Literal)

    The SassScript object that is the value of the variable

Raises:



38
39
40
41
42
43
44
45
# File 'lib/sass/script/variable.rb', line 38

def _perform(environment)
  raise SyntaxError.new("Undefined variable: \"$#{name}\".") unless val = environment.var(name)
  if val.is_a?(Number)
    val = val.dup
    val.original = nil
  end
  return val
end

#childrenArray<Node>

Returns an empty array.

Returns:

  • (Array<Node>)

    empty

See Also:



27
28
29
# File 'lib/sass/script/variable.rb', line 27

def children
  []
end

#inspect(opts = {}) ⇒ String Also known as: to_sass

Returns A string representation of the variable.

Returns:

  • (String)

    A string representation of the variable



17
18
19
20
# File 'lib/sass/script/variable.rb', line 17

def inspect(opts = {})
  return "!important" if name == "important"
  "$#{dasherize(name, opts)}"
end