kernel/common/eval.rb
# Evaluate and execute code given in the String.
#
Evaluate and execute code given in the String.
Evaluate and execute code given in the String .
def eval(string, binding=nil, filename="(eval)", lineno=1)
    if !binding
      binding = Binding.setup(VariableScope.of_sender,
                              CompiledMethod.of_sender,
                              StaticScope.of_sender)
    elsif binding.__kind_of__ Proc
      binding = binding.binding
    elsif !binding.__kind_of__ Binding
      raise ArgumentError, "unknown type of binding"
    end
    context = Compiler::Context.new binding.variables, binding.code
    compiled_method = Compiler::Utils.compile_string string, context, filename, lineno
    compiled_method.scope = binding.static_scope
    compiled_method.name = :__eval__
    yield compiled_method if block_given?
    script = CompiledMethod::Script.new
    script.path = filename
    compiled_method.scope.script = script
    compiled_method.compile
    be = BlockEnvironment.new
    be.under_context binding.variables, compiled_method
    if binding.from_proc? then
      be.proc_environment = binding.proc_environment
    end
    be.from_eval!
    be.call
  end
def eval ( string , binding = nil , filename = "(eval)" , lineno = 1 ) if ! binding binding = Binding . setup ( VariableScope . of_sender , CompiledMethod . of_sender , StaticScope . of_sender ) elsif binding . __kind_of__ Proc binding = binding . binding elsif ! binding . __kind_of__ Binding raise ArgumentError , "unknown type of binding" end context = Compiler :: Context . new binding . variables , binding . code compiled_method = Compiler :: Utils . compile_string string , context , filename , lineno compiled_method . scope = binding . static_scope compiled_method . name = :__eval__ yield compiled_method if block_given? script = CompiledMethod :: Script . new script . path = filename compiled_method . scope . script = script compiled_method . compile be = BlockEnvironment . new be . under_context binding . variables , compiled_method if binding . from_proc? then be . proc_environment = binding . proc_environment end be . from_eval! be . call end
Evaluate and execute code given in the String.
Evaluate and execute code given in the String .
# This has to be setup so __FILE__ works in eval. # Internalize it now, since we're going to springboard to it as a block. # Pass the BlockEnvironment this binding was created from # down into the new BlockEnvironment we just created. # This indicates the "declaration trace" to the stack trace # mechanisms, which can be different from the "call trace" # in the case of, say: eval("caller", a_proc_instance)
string
<not_specific>
binding
<not_specific>
filename
<not_specific>
lineno
<not_specific>