Class: LtdTemplate::Code::Call

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

Instance Method Summary collapse

Methods inherited from LtdTemplate::Code

#inspect, #rubyversed

Constructor Details

#initialize(template, target, method, parameters) ⇒ Call

Initialize a method call object.

Parameters:



18
19
20
21
# File 'lib/ltdtemplate/code/call.rb', line 18

def initialize (template, target, method, parameters)
	super template
	@target, @method, @parameters = target, method, parameters
end

Instance Method Details

#evaluate(opts = {}) ⇒ Object

Return the result of executing the call.

Parameters:

  • opts (Hash) (defaults to: {})

    Option hash

Options Hash (opts):

  • :method (String)

    A method to call on the return value



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ltdtemplate/code/call.rb', line 27

def evaluate (opts = {})
	# Increase the call count and call depth.
	# RESOURCE calls: Total number of method calls
	@template.use :calls
	# RESOURCE call_depth: The current method call depth
	@template.use :call_depth

	# Invoke the method call that we encode against the target.
	result = rubyversed(@target).evaluate({ :method => @method,
	  :parameters => rubyversed(@parameters).evaluate })

	# Decrease the call depth.
	@template.use :call_depth, -1

	# Invoke the method call requested by our invoker against the result.
	result = rubyversed(result).evaluate({ :method => opts[:method],
	  :parameters => opts[:parameters] }) if opts[:method]

	result
end