Class: LtdTemplate::Value::Code_Block

Inherits:
Object
  • Object
show all
Includes:
LtdTemplate::Value
Defined in:
lib/ltdtemplate/value.rb,
lib/ltdtemplate/value/code_block.rb

Instance Attribute Summary collapse

Attributes included from LtdTemplate::Value

#runtime_methods

Instance Method Summary collapse

Methods included from LtdTemplate::Value

#do_methods, #do_run_method, included, #inspect, #rubyversed, #tpl_boolean

Constructor Details

#initialize(template, code) ⇒ Code_Block

Returns a new instance of Code_Block.



20
21
22
23
# File 'lib/ltdtemplate/value/code_block.rb', line 20

def initialize (template, code)
  super template
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



18
19
20
# File 'lib/ltdtemplate/value/code_block.rb', line 18

def code
  @code
end

Instance Method Details

#evaluate(opts = {}) ⇒ Object

Evaluate supported methods on code blocks. Most methods are passed to the code block.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ltdtemplate/value/code_block.rb', line 27

def evaluate (opts = {})
  case opts[:method]
  when nil then self
  when 'class' then 'Code'
  when 'type' then 'code'
  else
 @template.push_namespace opts[:method], opts[:parameters],
   :target => (opts[:target] || self)
 result = rubyversed(@code).evaluate
 @template.pop_namespace
 result
  end
end

#tpl_textObject

In contrast to an implied code block, an uncalled explicit code block generates no template output.



43
# File 'lib/ltdtemplate/value/code_block.rb', line 43

def tpl_text; ''; end