Inversion::RenderState::

Scope

class
Superclass
BasicObject

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.

Public Class Methods

anchor
new( locals={}, fragments={} )

Create a new RenderState::Scope with its initial tag locals set to locals.

# File lib/inversion/renderstate.rb, line 24
def initialize( locals={}, fragments={} )
        @locals = locals
        @fragments = fragments
end

Public Instance Methods

anchor
+( values )

Return a copy of the receiving Scope merged with the given values, which can be either another Scope or a Hash.

# File lib/inversion/renderstate.rb, line 44
def +( values )
        return Scope.new( self.__locals__.merge(values), self.__fragments__ )
end
anchor
[]( name )

Return the tag local with the specified name.

# File lib/inversion/renderstate.rb, line 31
def []( name )
        return @locals[ name.to_sym ]
end
anchor
[]=( name, value )

Set the tag local with the specified name to value.

# File lib/inversion/renderstate.rb, line 37
def []=( name, value )
        @locals[ name.to_sym ] = value
end
anchor
__fragments__()

Returns the Hash of rendered fragments that belong to this scope.

# File lib/inversion/renderstate.rb, line 57
def __fragments__
        return @fragments
end
anchor
__locals__()

Return the Hash of tag locals the belongs to this scope.

# File lib/inversion/renderstate.rb, line 50
def __locals__
        return @locals
end
Also aliased as: to_hash
anchor
to_hash()
Alias for: __locals__

Protected Instance Methods

anchor
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.

# File lib/inversion/renderstate.rb, line 68
def method_missing( sym, *args, &block )
        return super unless sym =~ /^\w+$/
        return @locals[ sym ].nil? ? @fragments[ sym ] : @locals[ sym ]
end