Class: Liquidscript::ICR::Variable

Inherits:
Object
  • Object
show all
Includes:
Representable
Defined in:
lib/liquidscript/icr/variable.rb

Overview

Represents a variable. It can hold a value, but it will not be used to reconstruct the variable itself.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Representable

#to_a!, #to_ary, #to_sexp, #to_yaml

Constructor Details

#initialize(context, name) ⇒ Variable



30
31
32
33
34
# File 'lib/liquidscript/icr/variable.rb', line 30

def initialize(context, name)
  @context = context
  @name = name
  @value = nil
end

Instance Attribute Details

#contextContext (readonly)

The context in which this variable exists. The variable should exist in one and only one context, but can be used in contexts other than its own.



13
14
15
# File 'lib/liquidscript/icr/variable.rb', line 13

def context
  @context
end

#nameSymbol (readonly)

The name of the variable that this represents. This will be used in both ICR and in the final output.



19
20
21
# File 'lib/liquidscript/icr/variable.rb', line 19

def name
  @name
end

#valueCode

The set that describes the value of this variable. The set just so happens to describe the value of the variable; it is not used to define the variable’s value.



26
27
28
# File 'lib/liquidscript/icr/variable.rb', line 26

def value
  @value
end

Instance Method Details

#parameter!self

Marks this variable as an argument to a function. This is to let the context know not to show it in certain cases.



47
48
49
50
# File 'lib/liquidscript/icr/variable.rb', line 47

def parameter!
  @parameter = true
  self
end

#parameter?Boolean

Whether or not the variable is an argument to a function.

See Also:

  • Liquidscript::ICR::Variable.{{#parameter!}


56
57
58
# File 'lib/liquidscript/icr/variable.rb', line 56

def parameter?
  @parameter
end

#to_aArray<(Symbol, Symbol)>

Turns the variable into an array.



63
64
65
# File 'lib/liquidscript/icr/variable.rb', line 63

def to_a
  [:_variable, @name]
end

#typeSymbol

Make this class compatible with the #type based system.



39
40
41
# File 'lib/liquidscript/icr/variable.rb', line 39

def type
  :variable
end