public function expose($name, $function = null, $as = 'function')
    {
        $this->assertViewVariableName($name);
        
        if ($as === 'function') {
            $function = new \Twig_SimpleFunction($name, $function ?: $name);
            $this->getTwig()->addFunction($function);
        } elseif ($as === 'filter') {
            $filter = new \Twig_SimpleFilter($name, $function ?: $name);
            $this->getTwig()->addFilter($filter);
        } else {
            $not = is_string($as) ? "'$as'" : gettype($as);
            throw new \InvalidArgumentException("You can create either a 'function' or 'filter', not a $not");
        }

        return $this;
    }