Module Erubis::RubyEvaluator
In: erubis/evaluator.rb

evaluator for Ruby

Methods

def_method   evaluate   result  

Included Modules

Evaluator

Public Instance methods

if object is an Class or Module then define instance method to it, else define singleton method to it.

[Source]

# File erubis/evaluator.rb, line 75
    def def_method(object, method_name, filename=nil)
      m = object.is_a?(Module) ? :module_eval : :instance_eval
      object.__send__(m, "def #{method_name}; #{@src}; end", filename || @filename || '(erubis)')
    end

invoke context.instance_eval(@src)

[Source]

# File erubis/evaluator.rb, line 66
    def evaluate(context=Context.new)
      context = Context.new(context) if context.is_a?(Hash)
      #return context.instance_eval(@src, @filename || '(erubis)')
      @_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)')
      return context.instance_eval(&@_proc)
    end

eval(@src) with binding object

[Source]

# File erubis/evaluator.rb, line 54
    def result(_binding_or_hash=TOPLEVEL_BINDING)
      _arg = _binding_or_hash
      if _arg.is_a?(Hash)
        ## load _context data as local variables by eval
        #eval _arg.keys.inject("") { |s, k| s << "#{k.to_s} = _arg[#{k.inspect}];" }
        eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join
        _arg = binding()
      end
      return eval(@src, _arg, (@filename || '(erubis)'))
    end

[Validate]