Inversion::RenderState::
Scope
class
An encapsulation of the scope in which the bodies of tags evaluate. It’s used to provide a controlled, isolated namespace which remains the same from tag to tag.
new( locals={}, fragments={} )
Create a new RenderState::Scope with its initial tag locals set to ‘locals`.
def initialize( locals={}, fragments={} )
@locals = locals
@fragments = fragments
end
Return a copy of the receiving Scope merged with the given ‘values`, which can be either another Scope or a Hash.
def +( values )
return Scope.new( self.__locals__.merge(values), self.__fragments__ )
end
Return the tag local with the specified ‘name`.
def []( name )
return @locals[ name.to_sym ]
end
Set the tag local with the specified ‘name` to `value`.
def []=( name, value )
@locals[ name.to_sym ] = value
end
Returns the Hash of rendered fragments that belong to this scope.
def __fragments__
return @fragments
end
Return the Hash of tag locals the belongs to this scope.
def __locals__
return @locals
end
Protected Instance Methods
method_missing( sym, *args, &block )
The main trickery behind this class – intercept tag locals as method calls and map them into values from the Scope’s locals.
def method_missing( sym, *args, &block )
return super unless sym =~ /^\w+$/
return @locals[ sym ].nil? ? @fragments[ sym ] : @locals[ sym ]
end