module Erubis::RubyEvaluator

def self.supported_properties # :nodoc:

:nodoc:
def self.supported_properties    # :nodoc:
  list = Evaluator.supported_properties
  return list
end

def def_method(object, method_name, filename=nil)

# else define singleton method to it.
# if object is an Class or Module then define instance method to it,
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

def evaluate(_context=Context.new)

# invoke context.instance_eval(@src)
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)')
  @_proc ||= eval("proc { #{@src} }", binding(), @filename || '(erubis)')
  return _context.instance_eval(&@_proc)
end

def result(_binding_or_hash=TOPLEVEL_BINDING)

# eval(@src) with binding object
def result(_binding_or_hash=TOPLEVEL_BINDING)
  _arg = _binding_or_hash
  if _arg.is_a?(Hash)
    _b = binding()
    eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join, _b
  elsif _arg.is_a?(Binding)
    _b = _arg
  elsif _arg.nil?
    _b = binding()
  else
    raise ArgumentError.new("#{self.class.name}#result(): argument should be Binding or Hash but passed #{_arg.class.name} object.")
  end
  return eval(@src, _b, (@filename || '(erubis'))
end