Class: Liquidscript::ICR::Variable
- Inherits:
-
Object
- Object
- Liquidscript::ICR::Variable
- 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
-
#context ⇒ Context
readonly
The context in which this variable exists.
-
#name ⇒ Symbol
readonly
The name of the variable that this represents.
-
#value ⇒ Code
The set that describes the value of this variable.
Instance Method Summary collapse
-
#initialize(context, name) ⇒ Variable
constructor
A new instance of Variable.
-
#parameter! ⇒ self
Marks this variable as an argument to a function.
-
#parameter? ⇒ Boolean
Whether or not the variable is an argument to a function.
-
#to_a ⇒ Array<(Symbol, Symbol)>
Turns the variable into an array.
-
#type ⇒ Symbol
Make this class compatible with the #type based system.
Methods included from Representable
Constructor Details
#initialize(context, name) ⇒ Variable
Returns a new instance of 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
#context ⇒ Context (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 |
#name ⇒ Symbol (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 |
#value ⇒ Code
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.
56 57 58 |
# File 'lib/liquidscript/icr/variable.rb', line 56 def parameter? @parameter end |
#to_a ⇒ Array<(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 |
#type ⇒ Symbol
Make this class compatible with the #type based system.
39 40 41 |
# File 'lib/liquidscript/icr/variable.rb', line 39 def type :variable end |