Code Review: RubyScopes2

tfpt review “/shelveset:RubyScopes2;REDMOND\tomat”


Deletes IDynamicObject and GlobalsDictionary types and Scope.GetKeys
Adds a default implementation for ScriptCode.Run that creates a new
scope and calls Run(scope).
Adds assertions to ContractUtils.Invariant.


RubyScope fixes and refactoring.

This change enables top-level hosted code to define instance methods
in DLR scope. It is no longer necessary to define them as singleton
Ruby engine executes the hosted code as if it was executed using
instance_eval on a proc. The behavior is the same except for control
flow - break or retry on top-level throws an exception as it does in

This unit test illustrates the new behavior:

          // When executed without a scope top-level methods are 

defined on Object (as in MRI):
Engine.Execute(“def foo; 1; end”);
Assert(Context.ObjectClass.GetMethod(“foo”) != null);

          // When executed against a scope top-level methods are 

defined on main singleton (not on Object) and also stored in the scope:
var scope = Engine.CreateScope();
Engine.Execute(“def bar; 1; end”, scope);
Assert(Context.ObjectClass.GetMethod(“bar”) == null);
Assert(scope.GetVariable(“bar”) != null);

Fixes bug in top-level scope compilation - variables from the scope
were not bound properly:

          var compiled = 

scope = Engine.CreateScope();
scope.SetVariable(“some_variable”, “foo”);
Assert(compiled.Execute(scope) == “foo”);


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs