kernel/common/eval.rb
#--
# These have to be aliases, not methods that call instance eval, because we
# need to pull in the binding of the person that calls them, not the
# intermediate binding.
#++
These have to be aliases, not methods that call instance eval, because we
need to pull in the binding of the person that calls them, not the
intermediate binding.
These have to be aliases not methods that call instance eval because we need to pull in the binding of the person that calls them not the intermediate binding .
def module_eval(string=Undefined, filename="(eval)", line=1, &prc)
    if prc
      unless string.equal?(Undefined)
        raise ArgumentError, "cannot pass both string and proc"
      end
      env = prc.block
      static_scope = env.method.scope.using_current_as(self)
      return env.call_under(self, static_scope, self)
    elsif string.equal?(Undefined)
      raise ArgumentError, 'block not supplied'
    end
    variables = VariableScope.of_sender
    method = CompiledMethod.of_sender
    context = Compiler::Context.new variables, method
    string = StringValue(string)
    compiled_method = Compiler::Utils.compile_string string, context, filename, line
    ss = StaticScope.new self, StaticScope.of_sender
    script = CompiledMethod::Script.new
    script.path = filename
    ss.script = script
    compiled_method.scope = ss
    compiled_method.compile
    be = BlockEnvironment.new
    be.from_eval!
    be.under_context variables, compiled_method
    be.call_under self, ss, self
  end
def module_eval ( string = Undefined , filename = "(eval)" , line = 1 , & prc ) if prc unless string . equal? ( Undefined ) raise ArgumentError , "cannot pass both string and proc" end env = prc . block static_scope = env . method . scope . using_current_as ( self ) return env . call_under ( self , static_scope , self ) elsif string . equal? ( Undefined ) raise ArgumentError , 'block not supplied' end variables = VariableScope . of_sender method = CompiledMethod . of_sender context = Compiler :: Context . new variables , method string = StringValue ( string ) compiled_method = Compiler :: Utils . compile_string string , context , filename , line ss = StaticScope . new self , StaticScope . of_sender script = CompiledMethod :: Script . new script . path = filename ss . script = script compiled_method . scope = ss compiled_method . compile be = BlockEnvironment . new be . from_eval! be . under_context variables , compiled_method be . call_under self , ss , self end
These have to be aliases, not methods that call instance eval, because we
need to pull in the binding of the person that calls them, not the
intermediate binding.
These have to be aliases not methods that call instance eval because we need to pull in the binding of the person that calls them not the intermediate binding .
# we have a custom version with the prc, rather than using instance_exec # so that we can setup the StaticScope properly. # Return a copy of the BlockEnvironment with the receiver set to self # The staticscope of a module_eval CM is the receiver of module_eval # This has to be setup so __FILE__ works in eval. # The gist of this code is that we need the receiver's static scope # but the caller's binding to implement the proper constant behavior
string
<not_specific>
filename
<not_specific>
line
<not_specific>
prc
<not_specific>