Class: Templater::Variables

Inherits:
OpenStruct show all
Defined in:
lib/templater.rb

Instance Method Summary collapse

Methods inherited from OpenStruct

#[], #[]=, #to_hash

Constructor Details

#initialize(delegator = nil, variables = {}, &on_error) ⇒ Variables

Returns a new instance of Variables.



23
24
25
26
27
# File 'lib/templater.rb', line 23

def initialize(delegator=nil, variables={}, &on_error)
	super(variables)
	@delegator = delegator
	@on_error  = on_error || RaiseExceptions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/templater.rb', line 29

def method_missing(m, *a, &b)
	if @table.key?(m) || m.to_s =~ /=$/ then
		super
	elsif @delegator && @delegator.respond_to?(m) then
		@delegator.send(m, *a, &b) if @delegator
	else
		raise NameError, "undefined local variable or method `#{m}'"
	end
rescue Exception => e
	@on_error.call(e)
end

Instance Method Details

#inspectObject



41
42
43
# File 'lib/templater.rb', line 41

def inspect
	@table.inspect
end