Forum: IronRuby Code Review: RubyScopes2

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Tomas M. (Guest)
on 2009-04-29 07:31
(Received via mailing list)
Attachment: RubyScopes2.diff (0 Bytes)
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<string>(scope) == "foo");

This topic is locked and can not be replied to.