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={} )

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

# File lib/inversion/renderstate.rb, line 24
def initialize( locals={} )
        @locals = locals
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 43
def +( values )
        return Scope.new( @locals.merge(values) )
end
anchor
[]( name )

Return the tag local with the specified name.

# File lib/inversion/renderstate.rb, line 30
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 36
def []=( name, value )
        @locals[ name.to_sym ] = value
end
anchor
__locals__()

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

# File lib/inversion/renderstate.rb, line 49
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 61
def method_missing( sym, *args, &block )
        return super unless sym =~ %r^\w+$/
        @locals[ sym ]
end