Class: LtdTemplate::Code::Variable
- Inherits:
-
LtdTemplate::Code
- Object
- LtdTemplate::Code
- LtdTemplate::Code::Variable
- Defined in:
- lib/ltdtemplate/code/variable.rb
Instance Method Summary collapse
-
#evaluate(opts = {}) ⇒ Object
Evaluate.
-
#initialize(template, name) ⇒ Variable
constructor
A new instance of Variable.
-
#namespace ⇒ Object
Return the namespace in which this variable currently resides (or would reside, if it doesn’t currently exist).
Methods inherited from LtdTemplate::Code
Constructor Details
#initialize(template, name) ⇒ Variable
Returns a new instance of Variable.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ltdtemplate/code/variable.rb', line 11 def initialize (template, name) super template if name.size > 1 && (name[0] == '@' || name[0] == '^') # @var is in the root namespace # ^var is in the parent namespace @modifier = name[0] @name = name[1..-1] @name = @name.to_i if @name =~ /^(?:0|[1-9]\d*)$/ else # Standard bottom-to-top namespace search variable @modifier = nil @name = name end end |
Instance Method Details
#evaluate(opts = {}) ⇒ Object
Evaluate
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ltdtemplate/code/variable.rb', line 29 def evaluate (opts = {}) case opts[:method] when '=', '?=' if opts[:method] != '?=' || self.namespace[@name].nil? params = opts[:parameters] params = params[0] if params.is_a? LtdTemplate::Univalue self.namespace[@name] = params end nil else self.namespace[@name] = "" if opts[:method] == 'methods' && self.namespace[@name].nil? rubyversed(self.namespace[@name]).evaluate opts end end |
#namespace ⇒ Object
Return the namespace in which this variable currently resides (or would reside, if it doesn’t currently exist).
49 50 51 52 53 54 55 56 |
# File 'lib/ltdtemplate/code/variable.rb', line 49 def namespace case @modifier when '@' then base = @template.namespace.root when '^' then base = @template.namespace.parent || @template.namespace else base = @template.namespace end base.find_item(@name) || base end |