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

#line, #options

Instance Method Summary collapse

Methods inherited from Node

#dasherize, #opts, #perform

Constructor Details

#initialize(name) ⇒ Variable

Returns a new instance of Variable.

Parameters:



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

def initialize(name)
  @name = name
  @underscored_name = name.gsub(/-/,"_")
  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

#underscored_nameString (readonly)

The underscored name of the variable.

Returns:



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

def underscored_name
  @underscored_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:



48
49
50
51
52
53
54
55
# File 'lib/sass/script/variable.rb', line 48

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:



32
33
34
# File 'lib/sass/script/variable.rb', line 32

def children
  []
end

#deep_copy

See Also:



37
38
39
# File 'lib/sass/script/variable.rb', line 37

def deep_copy
  dup
end

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

Returns A string representation of the variable.

Returns:

  • (String)

    A string representation of the variable



23
24
25
# File 'lib/sass/script/variable.rb', line 23

def inspect(opts = {})
  "$#{dasherize(name, opts)}"
end