Module | Erubis::RubyEvaluator |
In: |
lib/erubis/evaluator.rb
|
evaluator for Ruby
if object is an Class or Module then define instance method to it, else define singleton method to it.
# File lib/erubis/evaluator.rb, line 80 80: def def_method(object, method_name, filename=nil) 81: m = object.is_a?(Module) ? :module_eval : :instance_eval 82: object.__send__(m, "def #{method_name}; #{@src}; end", filename || @filename || '(erubis)') 83: end
invoke context.instance_eval(@src)
# File lib/erubis/evaluator.rb, line 70 70: def evaluate(_context=Context.new) 71: _context = Context.new(_context) if _context.is_a?(Hash) 72: #return _context.instance_eval(@src, @filename || '(erubis)') 73: #@_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)') 74: @_proc ||= eval("proc { #{@src} }", binding(), @filename || '(erubis)') 75: return _context.instance_eval(&@_proc) 76: end
eval(@src) with binding object
# File lib/erubis/evaluator.rb, line 54 54: def result(_binding_or_hash=TOPLEVEL_BINDING) 55: _arg = _binding_or_hash 56: if _arg.is_a?(Hash) 57: _b = binding() 58: eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join, _b 59: elsif _arg.is_a?(Binding) 60: _b = _arg 61: elsif _arg.nil? 62: _b = binding() 63: else 64: raise ArgumentError.new("#{self.class.name}#result(): argument should be Binding or Hash but passed #{_arg.class.name} object.") 65: end 66: return eval(@src, _b, (@filename || '(erubis')) 67: end