edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs;C1221149
File: HostingTests.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs;C1221149  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs;Scopes3
@@ -263,6 +263,17 @@
 IronRuby.globals.z = IronRuby.globals.x + FooBar
 ");
             Assert(Runtime.Globals.GetVariable<int>("z") == 3);
+
+#if !CLR2
+            dynamic scope = Engine.CreateScope();
+            Engine.Execute(@"def foo; 1; end", scope);
+
+            RubyMethod method = (RubyMethod)scope.foo;
+            Assert(method.Name == "foo");
+
+            object value = scope.foo();
+            Assert((int)value == 1);
+#endif
         }
 
         public void RubyHosting_Scopes1() {
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;C1221149
File: LoaderTests.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;C1221149  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;Scopes3
@@ -128,14 +128,7 @@
                 File.WriteAllText(Path.Combine(temp, "a.py"), @"
 print 'Hello from Python'
 ");
-                AssertOutput(delegate() {
-                    CompilerTest(@"
-require('a')
-");
-                }, @"
-Hello from Python
-");
-
+                AssertExceptionThrown<LoadError>(() => CompilerTest(@"require('a')"));
             } finally {
                 File.Delete("b.py");
             }
@@ -162,9 +155,9 @@
                 TestOutput(@"
 a = IronRuby.require('a')
 scopes = IronRuby.loaded_scripts.collect { |z| z.value }
-a.who_is_this.call
+a.who_is_this
 a.foo += 1
-a.bar.new.baz
+a.bar.baz             # a Python class is callable so we get Bar's instance from a.bar
 puts scopes[0].Foo
 ", @"
 Python
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IronRubyOps.cs;C1116095
File: IronRubyOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IronRubyOps.cs;C1116095  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IronRubyOps.cs;Scopes3
@@ -59,7 +59,7 @@
             object loaded;
             
             scope.RubyContext.Loader.LoadFile(
-                null, self, libraryName, LoadFlags.LoadOnce | LoadFlags.AppendExtensions | LoadFlags.ResolveLoaded, out loaded
+                null, self, libraryName, LoadFlags.LoadOnce | LoadFlags.AppendExtensions | LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded
             );
 
             Debug.Assert(loaded != null);
@@ -72,7 +72,7 @@
         [RubyMethod("load", RubyMethodAttributes.PublicSingleton)]
         public static object/*!*/ Load(RubyScope/*!*/ scope, RubyModule/*!*/ self, MutableString/*!*/ libraryName) {
             object loaded;
-            scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded, out loaded);
+            scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded);
             Debug.Assert(loaded != null);
             return loaded;
         }
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Ruby.cs;C1221149
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C1221149
File: Loader.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C1221149  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;Scopes3
@@ -38,6 +38,7 @@
         LoadIsolated = 2,
         AppendExtensions = 4,
         ResolveLoaded = 8,
+        AnyLanguage = 16,
 
         Require = LoadOnce | AppendExtensions,
     }
@@ -496,7 +497,13 @@
         private bool LoadFromPath(Scope globalScope, object self, string/*!*/ path, LoadFlags flags, out object loaded) {
             Assert.NotNull(path);
 
-            string[] sourceFileExtensions = DomainManager.Configuration.GetFileExtensions();
+            string[] sourceFileExtensions;
+            if ((flags & LoadFlags.AnyLanguage) != 0) {
+                sourceFileExtensions = DomainManager.Configuration.GetFileExtensions();
+            } else {
+                sourceFileExtensions = DomainManager.Configuration.GetFileExtensions(_context);
+            }
+
             ResolvedFile file = FindFile(path, (flags & LoadFlags.AppendExtensions) != 0, sourceFileExtensions);
             if (file == null) {
                 throw RubyExceptions.CreateLoadError(String.Format("no such file to load -- {0}", path));
@@ -586,7 +593,10 @@
 
         internal Scope Execute(Scope globalScope, ScriptCode/*!*/ code) {
             if (globalScope == null || code.LanguageContext != _context) {
-                globalScope = code.CreateScope();
+                if (globalScope == null) {
+                    globalScope = code.CreateScope();
+                }
+
                 if (code.SourceUnit.Path != null) {
                     LoadedScripts[Platform.GetFullPath(code.SourceUnit.Path)] = globalScope;
                 }
@@ -733,7 +743,7 @@
         }
 
         private List<string>/*!*/ GetExtensionsOfExistingFiles(string/*!*/ path, IEnumerable<string>/*!*/ extensions) {
-            // all extensions that could be appended to the path to get an sexisting file:
+            // all extensions that could be appended to the path to get an existing file:
             List<string> result = new List<string>();
             foreach (string extension in extensions) {
                 Debug.Assert(extension != null && extension.StartsWith("."));
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;C1240182
File: RubyContext.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;C1240182  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;Scopes3
@@ -2107,7 +2107,7 @@
 
         #endregion
 
-        #region Global Scope (TODO: thread-safe)
+        #region Global Scope (thread-safe)
 
         /// <summary>
         /// Creates a scope extension for a DLR scope unless it already exists for the given scope.
@@ -2115,7 +2115,6 @@
         internal RubyGlobalScope/*!*/ InitializeGlobalScope(Scope/*!*/ globalScope, bool createHosted, bool bindGlobals) {
             Assert.NotNull(globalScope);
 
-            // TODO: Scopes are not thread safe but should be!
             var scopeExtension = globalScope.GetExtension(ContextId);
             if (scopeExtension != null) {
                 return (RubyGlobalScope)scopeExtension;
@@ -2125,8 +2124,6 @@
             RubyClass mainSingleton = CreateMainSingleton(mainObject, null);
 
             RubyGlobalScope result = new RubyGlobalScope(this, globalScope, mainObject, createHosted);
-            globalScope.SetExtension(ContextId, result);
-
             if (bindGlobals) {
                 // method_missing:
                 mainSingleton.SetMethodNoEvent(this, Symbols.MethodMissing, 
@@ -2137,8 +2134,7 @@
 
                 mainSingleton.SetGlobalScope(result);
             }
-
-            return result;
+            return (RubyGlobalScope)globalScope.SetExtension(ContextId, result);
         }
 
         public override int ExecuteProgram(SourceUnit/*!*/ program) {
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyGlobalScope.cs;C966724
File: RubyGlobalScope.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyGlobalScope.cs;C966724  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyGlobalScope.cs;Scopes3
@@ -13,21 +13,27 @@
  *
  * ***************************************************************************/
 
+using System.Diagnostics;
+using System.Threading;
+using IronRuby.Builtins;
 using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
-using IronRuby.Builtins;
-using System.Diagnostics;
 
 namespace IronRuby.Runtime {
-    public class RubyGlobalScope : ScopeExtension {
-        private RubyContext/*!*/ _context;
-        private RubyObject/*!*/ _mainObject;
+    /// <summary>
+    /// DLR scope extension.
+    /// Thread safe.
+    /// </summary>
+    public sealed class RubyGlobalScope : ScopeExtension {
+        private readonly RubyContext/*!*/ _context;
+        private readonly RubyObject/*!*/ _mainObject;
+        private readonly bool _isHosted;
+
+        // interlocked:
         private RubyTopLevelScope _topLocalScope;
-        private bool _isHosted;
 
         public RubyContext/*!*/ Context {
             get { return _context; }
-            set { _context = value; }
         }
 
         public RubyClass/*!*/ MainSingleton {
@@ -44,10 +50,9 @@
 
         public RubyTopLevelScope TopLocalScope {
             get { return _topLocalScope; }
-            internal set { _topLocalScope = value; }
         }
 
-        public RubyGlobalScope(RubyContext/*!*/ context, Scope/*!*/ scope, RubyObject/*!*/ mainObject, bool isHosted)
+        internal RubyGlobalScope(RubyContext/*!*/ context, Scope/*!*/ scope, RubyObject/*!*/ mainObject, bool isHosted)
             : base(scope) {
             Assert.NotNull(context, scope, mainObject);
             Debug.Assert(mainObject.ImmediateClass.IsSingletonClass);
@@ -56,5 +61,9 @@
             _mainObject = mainObject;
             _isHosted = isHosted;
         }
+
+        internal RubyTopLevelScope/*!*/ SetTopLocalScope(RubyTopLevelScope/*!*/ scope) {
+            return Interlocked.CompareExchange(ref _topLocalScope, scope, null);
+        }
     }
 }
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs;C1233815
File: RubyScope.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs;C1233815  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs;Scopes3
@@ -944,7 +944,7 @@
                 );
 
                 scope.SetDebugName(bindGlobals ? "top-level-bound" : "top-level");
-                rubyGlobalScope.TopLocalScope = scope;
+                rubyGlobalScope.SetTopLocalScope(scope);
             } else {
                 // If we reuse a local scope from previous execution all local variables are accessed dynamically.
                 // Therefore we shouldn't have any new static local variables.
@@ -975,6 +975,8 @@
         public static object ScopeMethodMissing(RubyContext/*!*/ context, Scope/*!*/ globalScope, BlockParam block, object self, SymbolId name, object[]/*!*/ args) {
             Assert.NotNull(context, globalScope);
 
+            // TODO: invoke member:
+
             string str = SymbolTable.IdToString(name);
             if (str.LastCharacter() == '=') {
                 if (args.Length != 1) {
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs;C1221101
File: InteropBinder.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs;C1221101  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs;Scopes3
@@ -184,11 +184,17 @@
 
         internal class InvokeMember : InvokeMemberBinder, IInteropBinder {
             private readonly RubyContext/*!*/ _context;
+            private readonly string _mangled;
 
             internal InvokeMember(RubyContext/*!*/ context, string/*!*/ name, CallInfo/*!*/ callInfo)
+                : this(context, name, null, callInfo) {
+            }
+
+            private InvokeMember(RubyContext/*!*/ context, string/*!*/ name, string mangled, CallInfo/*!*/ callInfo)
                 : base(name, false, callInfo) {
                 Assert.NotNull(context);
                 _context = context;
+                _mangled = mangled;
             }
 
             public RubyContext Context {
@@ -206,7 +212,14 @@
                 }
 #endif
 
-                return FallbackInvokeMember(this, Name, CallInfo, target, args, errorSuggestion);
+                if (_mangled == null) {
+                    string unmangled = RubyUtils.TryUnmangleMethodName(Name);
+                    if (unmangled != null) {
+                        return new InvokeMember(_context, unmangled, Name, CallInfo).Bind(target, args);
+                    }
+                }
+
+                return FallbackInvokeMember(this, _mangled ?? Name, CallInfo, target, args, errorSuggestion);
             }
 
             internal static DynamicMetaObject FallbackInvokeMember(IInteropBinder/*!*/ binder, string/*!*/ methodName, CallInfo/*!*/ callInfo,
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs;C1162930
File: RubyBinder.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs;C1162930  (server)    10/28/2009 11:46 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs;Scopes3
@@ -27,6 +27,7 @@
 using System.Threading;
 using System.Diagnostics;
 using IronRuby.Runtime.Conversions;
+using System.Reflection;
 
 namespace IronRuby.Runtime.Calls {
     public sealed class RubyBinder : DefaultBinder {
@@ -81,7 +82,7 @@
             return result;
         }
 
-#if DEBUG && !SILVERLIGHT && CLR2
+#if DEBUG && !SILVERLIGHT
         // ExpressionWriter might call ToString on a live object that might dynamically invoke a method.
         // We need to prevent recursion in such case.
         [ThreadStatic]
@@ -89,11 +90,14 @@
 
         private static int _precompiledRuleCounter;
         private static int _ruleCounter;
+#if !CLR2
+        private static MethodInfo _dumpViewMethod; 
 #endif
+#endif
 
         [Conditional("DEBUG")]
         internal static void DumpPrecompiledRule(DynamicMetaObjectBinder/*!*/ action, MethodDispatcher/*!*/ dispatcher) {
-#if DEBUG && !SILVERLIGHT && CLR2
+#if DEBUG && !SILVERLIGHT
             if (RubyOptions.ShowRules) {
                 var oldColor = Console.ForegroundColor;
                 Console.ForegroundColor = ConsoleColor.Cyan;
@@ -107,7 +111,7 @@
 
         [Conditional("DEBUG")]
         internal static void DumpRule(DynamicMetaObjectBinder/*!*/ action, BindingRestrictions/*!*/ restrictions, Expression/*!*/ expr) {
-#if DEBUG && !SILVERLIGHT && CLR2
+#if DEBUG && !SILVERLIGHT
             if (RubyOptions.ShowRules) {
                 var oldColor = Console.ForegroundColor;
                 try {
@@ -117,8 +121,19 @@
                     if (!_DumpingExpression) {
                         var d = (restrictions != BindingRestrictions.Empty) ? Expression.IfThen(restrictions.ToExpression(), expr) : expr;
                         _DumpingExpression = true;
+#if CLR2
                         d.DumpExpression(Console.Out);
-                        Console.WriteLine();
+#else
+                        try {
+                            if (_dumpViewMethod == null) {
+                                _dumpViewMethod = typeof(Expression).GetMethod("get_DebugView", BindingFlags.NonPublic | BindingFlags.Instance);
+                            }
+                            Console.WriteLine(_dumpViewMethod.Invoke(d, ArrayUtils.EmptyObjects));
+                            Console.WriteLine();
+                        } catch {
+                            // nop
+                        }
+#endif
                     }
                 } finally {
                     _DumpingExpression = false;
===================================================================
