Module: Erubis::RubyEvaluator
- Includes:
- Evaluator
- Included in:
- Eruby, OptimizedEruby, PI::Eruby
- Defined in:
- lib/erubis/evaluator.rb
Overview
evaluator for Ruby
Instance Attribute Summary
Attributes included from Evaluator
Class Method Summary collapse
-
.supported_properties ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#def_method(object, method_name, filename = nil) ⇒ Object
if object is an Class or Module then define instance method to it, else define singleton method to it.
-
#evaluate(context = Context.new) ⇒ Object
invoke context.instance_eval(@src).
-
#result(_binding_or_hash = TOPLEVEL_BINDING) ⇒ Object
eval(@src) with binding object.
Methods included from Evaluator
Class Method Details
.supported_properties ⇒ Object
:nodoc:
48 49 50 51 |
# File 'lib/erubis/evaluator.rb', line 48 def self.supported_properties # :nodoc: list = Evaluator.supported_properties return list end |
Instance Method Details
#def_method(object, method_name, filename = nil) ⇒ Object
if object is an Class or Module then define instance method to it, else define singleton method to it.
75 76 77 78 |
# File 'lib/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 |
#evaluate(context = Context.new) ⇒ Object
invoke context.instance_eval(@src)
66 67 68 69 70 71 |
# File 'lib/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 |
#result(_binding_or_hash = TOPLEVEL_BINDING) ⇒ Object
eval(@src) with binding object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/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 |