Class: LtdTemplate::Code::Parameters

Inherits:
LtdTemplate::Code show all
Defined in:
lib/ltdtemplate/code/parameters.rb

Instance Attribute Summary

Attributes inherited from LtdTemplate::Code

#tpl_methods

Instance Method Summary collapse

Methods inherited from LtdTemplate::Code

#do_method, #do_set, #get_item, #has_item?, instance, #is_set?, #set_item, #set_value

Constructor Details

#initialize(template, positional = [], named = nil) ⇒ Parameters

Create a parameter list builder with code to generate positional values and possibly code to generate named values.



15
16
17
18
19
20
# File 'lib/ltdtemplate/code/parameters.rb', line 15

def initialize (template, positional = [], named = nil)
	super template

	# Save the code blocks for positional and named parameters.
	@positional, @named = positional, named
end

Instance Method Details

#get_value(opts = {}) ⇒ Object

Evaluate the code provided for the positional and named parameters and return a corresponding array t-value.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ltdtemplate/code/parameters.rb', line 26

def get_value (opts = {})
	positional = @positional.map { |val| val.get_value }
	named = {}
	if @named
 @named.each_slice(2) do |key, val|
		named[key.get_value.to_native] = val.get_value
 end
 scalar = false
	else
 scalar = positional.size == 1
	end
	@template.factory(:array).set_value(positional, named, scalar)
end