add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Methods/singleton_method_events.rb
File: singleton_method_events.rb
===================================================================
--- [no source file]
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Methods/singleton_method_events.rb;MoreEvents
@@ -1,0 +1,20 @@
+module Kernel
+  def singleton_method_added name
+    puts "#{self}##{name}"
+  end
+end
+
+class C
+  class << self
+    class << self
+      def bar
+      end
+    end
+    
+    def foo
+    end
+  end
+end
+
+require 'yaml'
+YAML.methods()
===================================================================
add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Methods/singleton_method_events2.rb
File: singleton_method_events2.rb
===================================================================
--- [no source file]
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Methods/singleton_method_events2.rb;MoreEvents
@@ -1,0 +1,55 @@
+class A
+  def self.m_sa
+  end
+end
+
+x = Object.new
+
+module Kernel
+    def singleton_method_added s
+      puts "Kernel: #{self}##{s}"
+    end
+
+    def self.singleton_method_added s
+      puts "s(Kernel): #{self}##{s}"
+    end
+end
+
+class << x
+  class << self
+    def singleton_method_added s
+      puts "S(x): #{self}##{s}"
+    end
+  end
+
+  def m_sx
+  end
+end
+
+class C
+  def self.singleton_method_added s
+    puts "S(C): #{self}##{s}"
+  end
+
+  def self.m_sc
+  end  
+end
+
+=begin
+
+
+
+
+#p Class.send :inherited, 1
+
+class B
+  def self.inherited name
+    puts name.class
+  end
+ 
+end
+
+class A < B
+end
+
+=end
\ No newline at end of file
===================================================================
add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Methods/to_proc.rb
File: to_proc.rb
===================================================================
--- [no source file]
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Methods/to_proc.rb;MoreEvents
@@ -1,0 +1,30 @@
+class B
+  def foo 
+     puts 'super'
+  end
+end
+
+class C < B
+  def foo x
+    super()
+    a = 1
+    puts 'foo'        
+  end
+end
+
+x = C.new
+m = x.method :foo
+p m
+1.times &m.to_proc
+
+def foo m
+  Proc.new { |*args| m.call(*args) }
+end
+
+#q = foo(m)
+
+z = m.to_proc
+eval("p local_variables", z)
+eval("p self", z)
+
+
===================================================================
add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Modules/inherited_event.rb
File: inherited_event.rb
===================================================================
--- [no source file]
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Modules/inherited_event.rb;MoreEvents
@@ -1,0 +1,115 @@
+class Class
+  def inherited s
+    p Object.constants.include?(s.name)
+
+    if s.name == "YAML::Syck::Resolver" then
+      raise IOError
+    end
+    if $raise then
+      $sub = s
+      puts "raise #{$raise}"
+      raise $raise
+    end
+    
+    puts "#{s} < #{self}"
+  end
+end
+
+class B
+  
+end
+
+class A < B
+end
+
+class << self
+  class << self
+    class << self
+    end
+  end  
+end
+
+puts '-'*25
+puts 'dup'
+puts '-'*25
+
+C = A.dup                          # no event
+
+puts '-'*25
+puts 'Struct'
+puts '-'*25
+
+S = Struct.new :foo, :bar do
+  puts self.new.foo
+  puts 'bar'
+end
+
+puts '-'*25
+
+$raise = 'xxx'
+begin
+  S = Struct.new :foo, :bar do
+    puts self.new.foo
+    puts 'bar'
+  end
+rescue
+  p $!
+end
+p $sub.public_instance_methods(false)
+p $sub.private_instance_methods(false)
+p $sub.protected_instance_methods(false)
+p $sub.singleton_methods(false)
+$raise = nil
+
+puts '-'*25
+puts 'Class.new'
+puts '-'*25
+
+X = Class.new B do
+  def bar
+  end
+  puts 'bar'
+end
+
+puts '-'*25
+
+$raise = 'hello'
+begin
+  X = Class.new B do
+    def bar
+    end
+    puts 'bar'
+  end
+rescue
+  p $!
+end
+p $sub.instance_methods(false)
+$raise = nil
+
+puts '-'*25
+puts 'class E < B'
+puts '-'*25
+
+$raise = 'hello'
+begin
+  class E < B
+    def bar
+    end
+    puts 'bar'
+  end
+rescue
+  p $!
+end
+p $sub.instance_methods(false)
+$raise = nil
+
+puts '-'*25
+puts 'yaml'
+puts '-'*25
+
+begin
+  require 'yaml'
+rescue
+  p $!
+end
+
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C445606
File: Initializers.Generated.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C445606  (server)    5/22/2008 10:58 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;MoreEvents
@@ -25,7 +25,6 @@
                 new System.Action<Ruby.Builtins.RubyModule>(LoadModule_Class),
                 new System.Action<Ruby.Builtins.RubyModule>(LoadClass_Class)
             );
-            Ruby.Builtins.RubyClass classRef0 = GetClass(typeof(System.ValueType));
             
             
             // Skipped primitive: __ClassSingleton
@@ -49,12 +48,9 @@
             #endif
             // Skipped primitive: Object
             ExtendModule(typeof(System.Collections.Generic.IDictionary<System.Object, System.Object>), new System.Action<Ruby.Builtins.RubyModule>(LoadSystem__Collections__Generic__IDictionary_Instance), null, new Ruby.Builtins.RubyModule[] {def16, });
-            ExtendModule(typeof(System.Collections.IEnumerable), new System.Action<Ruby.Builtins.RubyModule>(LoadSystem__Collections__IEnumerable_Instance), null, new Ruby.Builtins.RubyModule[] {def16, });
+            Ruby.Builtins.RubyModule def29 = ExtendModule(typeof(System.Collections.IEnumerable), new System.Action<Ruby.Builtins.RubyModule>(LoadSystem__Collections__IEnumerable_Instance), null, new Ruby.Builtins.RubyModule[] {def16, });
             ExtendModule(typeof(System.Collections.IList), new System.Action<Ruby.Builtins.RubyModule>(LoadSystem__Collections__IList_Instance), null, new Ruby.Builtins.RubyModule[] {def16, });
             ExtendModule(typeof(System.IComparable), new System.Action<Ruby.Builtins.RubyModule>(LoadSystem__IComparable_Instance), null, new Ruby.Builtins.RubyModule[] {def25, });
-            DefineGlobalClass("Time", typeof(System.DateTime), classRef0, new System.Action<Ruby.Builtins.RubyModule>(LoadTime_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadTime_Class), new Ruby.Builtins.RubyModule[] {def25, }, new System.Delegate[] {
-                new Microsoft.Scripting.Utils.Function<System.DateTime>(Ruby.Builtins.TimeOps.Create),
-            });
             DefineGlobalClass("Array", typeof(Ruby.Builtins.RubyArray), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadArray_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadArray_Class), new Ruby.Builtins.RubyModule[] {def16, }, new System.Delegate[] {
                 new Microsoft.Scripting.Utils.Function<Ruby.Builtins.RubyArray>(Ruby.Builtins.ArrayOps.CreateArray),
                 new Microsoft.Scripting.Utils.Function<System.Collections.IList, Ruby.Builtins.RubyArray>(Ruby.Builtins.ArrayOps.CreateArray),
@@ -65,7 +61,7 @@
                 new Microsoft.Scripting.Utils.Function<Microsoft.Scripting.Runtime.CodeContext, Ruby.Runtime.BlockParam, System.Object, System.Object>(Ruby.Builtins.ArrayOps.CreateArray),
             });
             DefineGlobalClass("Binding", typeof(Ruby.Builtins.Binding), Context.ObjectClass, null, null, Ruby.Builtins.RubyModule.EmptyArray, null);
-            DefineGlobalClass("ClrString", typeof(System.String), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadClrString_Instance), null, Ruby.Builtins.RubyModule.EmptyArray, null);
+            DefineGlobalClass("ClrString", typeof(System.String), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadClrString_Instance), null, new Ruby.Builtins.RubyModule[] {def29, }, null);
             DefineGlobalClass("Dir", typeof(Ruby.Builtins.RubyDir), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadDir_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadDir_Class), new Ruby.Builtins.RubyModule[] {def16, }, null);
             Ruby.Builtins.RubyClass def26 = Context.ExceptionClass = DefineGlobalClass("Exception", typeof(System.Exception), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadException_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadException_Class), Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] {
                 new Microsoft.Scripting.Utils.Function<Ruby.Builtins.MutableString, System.Exception>(Ruby.Builtins.ExceptionOps.Factory),
@@ -118,6 +114,9 @@
             });
             DefineGlobalClass("Symbol", typeof(Microsoft.Scripting.SymbolId), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadSymbol_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadSymbol_Class), Ruby.Builtins.RubyModule.EmptyArray, null);
             DefineGlobalClass("Thread", typeof(System.Threading.Thread), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadThread_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadThread_Class), Ruby.Builtins.RubyModule.EmptyArray, null);
+            DefineGlobalClass("Time", typeof(System.DateTime), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadTime_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadTime_Class), new Ruby.Builtins.RubyModule[] {def25, }, new System.Delegate[] {
+                new Microsoft.Scripting.Utils.Function<System.DateTime>(Ruby.Builtins.TimeOps.Create),
+            });
             Context.TrueClass = DefineGlobalClass("TrueClass", typeof(Ruby.Builtins.TrueClass), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadTrueClass_Instance), null, Ruby.Builtins.RubyModule.EmptyArray, null);
             DefineGlobalClass("UnboundMethod", typeof(Ruby.Builtins.UnboundMethod), Context.ObjectClass, new System.Action<Ruby.Builtins.RubyModule>(LoadUnboundMethod_Instance), null, Ruby.Builtins.RubyModule.EmptyArray, null);
             // Skipped primitive: Class
@@ -525,7 +524,7 @@
             module.DefineRuleGenerator("allocate", 0x29, Ruby.Builtins.ClassOps.GetInstanceAllocator());
             
             module.DefineLibraryMethod("inherited", 0x2a, new System.Delegate[] {
-                new Microsoft.Scripting.Utils.Action(Ruby.Builtins.ClassOps.Inherited),
+                new Microsoft.Scripting.Utils.Action<Ruby.Builtins.RubyClass, System.Object>(Ruby.Builtins.ClassOps.Inherited),
             });
             
             module.DefineLibraryMethod("initialize", 0x2a, new System.Delegate[] {
@@ -2420,6 +2419,18 @@
                 new Microsoft.Scripting.Utils.Function<Microsoft.Scripting.Runtime.CodeContext, System.Object, Ruby.Runtime.BlockParam, System.Object, System.Object[], System.Object>(Ruby.Builtins.Kernel.SendMessage),
             });
             
+            module.DefineLibraryMethod("singleton_method_added", 0x2a, new System.Delegate[] {
+                new Microsoft.Scripting.Utils.Action<System.Object, System.Object>(Ruby.Builtins.Kernel.MethodAdded),
+            });
+            
+            module.DefineLibraryMethod("singleton_method_removed", 0x2a, new System.Delegate[] {
+                new Microsoft.Scripting.Utils.Action<System.Object, System.Object>(Ruby.Builtins.Kernel.MethodRemoved),
+            });
+            
+            module.DefineLibraryMethod("singleton_method_undefined", 0x2a, new System.Delegate[] {
+                new Microsoft.Scripting.Utils.Action<System.Object, System.Object>(Ruby.Builtins.Kernel.MethodUndefined),
+            });
+            
             module.DefineLibraryMethod("singleton_methods", 0x29, new System.Delegate[] {
                 new Microsoft.Scripting.Utils.Function<Microsoft.Scripting.Runtime.CodeContext, System.Object, System.Boolean, Ruby.Builtins.RubyArray>(Ruby.Builtins.Kernel.GetSingletonMethods),
             });
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ClassOps.cs;C438696
File: ClassOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ClassOps.cs;C438696  (server)    5/22/2008 10:55 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ClassOps.cs;MoreEvents
@@ -50,11 +50,11 @@
         
         #endregion
 
-        #region Private Instance Methods // TODO
+        #region Private Instance Methods
 
         [RubyMethod("inherited", RubyMethodAttributes.PrivateInstance)]
-        public static void Inherited() {
-            throw new NotImplementedException("TODO");
+        public static void Inherited(RubyClass/*!*/ self, object subclass) {
+            // nop
         }
 
         #endregion
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Kernel.cs;C445606
File: Kernel.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Kernel.cs;C445606  (server)    5/22/2008 11:09 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Kernel.cs;MoreEvents
@@ -38,13 +38,29 @@
         //initialize_copy
         //location_of_caller
         //remove_instance_variable
-        //singleton_method_added
-        //singleton_method_removed
-        //singleton_method_undefined
         //y
 
+        #region singleton_method_(added|removed|undefined)
+
+        [RubyMethod("singleton_method_added", RubyMethodAttributes.PrivateInstance)]
+        public static void MethodAdded(object self, object methodName) {
+            // nop
+        }
+
+        [RubyMethod("singleton_method_removed", RubyMethodAttributes.PrivateInstance)]
+        public static void MethodRemoved(object self, object methodName) {
+            // nop
+        }
+
+        [RubyMethod("singleton_method_undefined", RubyMethodAttributes.PrivateInstance)]
+        public static void MethodUndefined(object self, object methodName) {
+            // nop
+        }
+
         #endregion
 
+        #endregion
+
         #region Private Instance & Singleton Methods
 
         // TODO: 1.8/1.9
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Struct.cs;C445606
File: Struct.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Struct.cs;C445606  (server)    5/22/2008 1:19 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Struct.cs;MoreEvents
@@ -457,6 +457,9 @@
         /// </summary>
         private static object Create(CodeContext/*!*/ context, BlockParam block, SymbolId className,  SymbolId[]/*!*/ attributeNames) {
             RubyExecutionContext ec = RubyUtils.GetExecutionContext(context);
+
+            // MRI: "inherited" event is triggered before he members are defined and the body is evaluated.
+            // Any exception thrown by the event will cancel struct initialization.
             RubyClass structClass = ec.GetClass(typeof(RubyStruct));
             RubyClass cls = ec.DefineClass(structClass, className, structClass);
 
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/TimeOps.cs;C443395
File: TimeOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/TimeOps.cs;C443395  (server)    5/22/2008 12:11 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/TimeOps.cs;MoreEvents
@@ -23,8 +23,7 @@
 
 namespace Ruby.Builtins {
 
-    [RubyClass("Time", Extends = typeof(DateTime))]
-    [Includes(typeof(Comparable))]
+    [RubyClass("Time", Extends = typeof(DateTime), Inherits = typeof(Object)), Includes(typeof(Comparable))]
     public static class TimeOps {
         readonly static DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); //January 1, 1970 00:00 UTC
 
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Initializer.cs;C443395
File: Initializer.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Initializer.cs;C443395  (server)    5/22/2008 12:14 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Initializer.cs;MoreEvents
@@ -25,6 +25,7 @@
 
     public abstract class LibraryInitializer {
         private RubyExecutionContext _context;
+        private bool _builtin;
 
         protected RubyExecutionContext/*!*/ Context {
             get { return _context; }
@@ -33,28 +34,29 @@
         protected LibraryInitializer() {
         }
 
-        internal void LoadModules(RubyExecutionContext/*!*/ context) {
+        internal void LoadModules(RubyExecutionContext/*!*/ context, bool builtin) {
             Assert.NotNull(context);
             _context = context;
+            _builtin = builtin;
             LoadModules();
         }
 
         protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, RubyClass/*!*/ super, 
             Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, RubyModule[]/*!*/ mixins, Delegate[] factories) {
 
-            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories);
+            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories, _builtin);
             _context.ObjectClass.SetConstant(result.Name, result);
             return result;
         }
 
         protected RubyClass/*!*/ DefineClass(string/*!*/ name, Type/*!*/ type, RubyClass/*!*/ super, 
             Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, RubyModule[]/*!*/ mixins, Delegate[] factories) {
-            return _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories);
+            return _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories, _builtin);
         }
 
         protected RubyClass/*!*/ ExtendClass(Type/*!*/ type, Action<RubyModule> instanceTrait, Action<RubyModule> classTrait,
             RubyModule[]/*!*/ mixins, Delegate[] factories) {
-            return _context.DefineLibraryClass(null, type, instanceTrait, classTrait, null, mixins, factories);
+            return _context.DefineLibraryClass(null, type, instanceTrait, classTrait, null, mixins, factories, _builtin);
         }
 
         protected RubyModule/*!*/ DefineGlobalModule(string/*!*/ name, Type/*!*/ type, Action<RubyModule> instanceTrait,
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.cs;C443395
File: Proc.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.cs;C443395  (server)    5/22/2008 10:49 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.cs;MoreEvents
@@ -39,6 +39,14 @@
     public class Proc : IDynamicObject {
         private static int _CurrentId = 0;
 
+        // Self object captured by the block definition, if any.
+        // Although we could load self from scope in Ruby defined blocks, we cannot do so when we don't have a scope.
+        private readonly object _self;
+
+        // Local scope inside the proc captured by the block definition;
+        // Null for block defined out of Ruby;
+        private readonly RubyScope _scope;
+                
         private readonly RubyBlockInfo/*!*/ _info;
         private ProcKind _kind;
 
@@ -62,19 +70,21 @@
         public int Id { get { return _id; } }
 
         public object Self { 
-            get { return _info.Self; }
+            get { return _self; }
         }
 
         public RubyScope LocalScope {
-            get { return _info.LocalScope; }
+            get { return _scope; }
         }
 
         internal static PropertyInfo/*!*/ IdProperty { get { return typeof(Proc).GetProperty("Id"); } }
         internal static PropertyInfo/*!*/ SelfProperty { get { return typeof(Proc).GetProperty("Self"); } }
 
-        internal Proc(ProcKind kind, RubyBlockInfo/*!*/ info) {
+        internal Proc(ProcKind kind, object self, RubyScope scope, RubyBlockInfo/*!*/ info) {
             Assert.NotNull(info);
             _kind = kind;
+            _self = self;
+            _scope = scope;
             _info = info;
             _id = Interlocked.Increment(ref _CurrentId);
         }
@@ -186,7 +196,7 @@
         }
 
         public static Proc/*!*/ Create(Delegate/*!*/ clrMethod, object self, int parameterCount) {
-            return new Proc(ProcKind.Block, new RubyBlockInfo(clrMethod, self, null, parameterCount, false, false));
+            return new Proc(ProcKind.Block, self, null, new RubyBlockInfo(clrMethod, parameterCount, false, false));
         }
 
         // The following methods are block implementations, there fore they need to have signature like a block.
@@ -213,7 +223,7 @@
         /// </summary>
         /// <returns></returns>
         public Proc/*!*/ ToLambda() {
-            Proc result = new Proc(ProcKind.Lambda, _info);
+            Proc result = new Proc(ProcKind.Lambda, _self, _scope, _info);
             result._owner = _owner;
             result._converter = _converter;
             return result;
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs;C444795
File: RubyClass.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs;C444795  (server)    5/22/2008 2:00 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs;MoreEvents
@@ -169,6 +169,9 @@
         internal static object CreateAnonymousClass(CodeContext/*!*/ context, BlockParam body, [Optional]RubyClass superClass) {
             RubyExecutionContext ec = RubyUtils.GetExecutionContext(context);
             RubyModule owner = ec.GetInnerMostModule(context);
+            
+            // MRI is inconsistent here, it triggers "inherited" event after the body of the method is evaluated.
+            // In all other cases the order is event first, body next.
             RubyClass newClass = ec.DefineClass(owner, SymbolId.Empty, superClass ?? ec.ObjectClass);
             return (body != null) ? RubyUtils.EvaluateInModule(context, newClass, body, newClass) : newClass;
         }
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;C444795
File: Symbols.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;C444795  (server)    5/22/2008 11:06 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;MoreEvents
@@ -30,6 +30,10 @@
         public static readonly SymbolId MethodAdded = SymbolTable.StringToId("method_added");
         public static readonly SymbolId MethodRemoved = SymbolTable.StringToId("method_removed");
         public static readonly SymbolId MethodUndefined = SymbolTable.StringToId("method_undefined");
+        public static readonly SymbolId SingletonMethodAdded = SymbolTable.StringToId("singleton_method_added");
+        public static readonly SymbolId SingletonMethodRemoved = SymbolTable.StringToId("singleton_method_removed");
+        public static readonly SymbolId SingletonMethodUndefined = SymbolTable.StringToId("singleton_method_undefined");
+        public static readonly SymbolId Inherited = SymbolTable.StringToId("inherited");
         public static readonly SymbolId RespondTo = SymbolTable.StringToId("respond_to?");
         public static readonly SymbolId ToProc = SymbolTable.StringToId("to_proc");
         public static readonly SymbolId ToS = SymbolTable.StringToId("to_s");
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C444795
File: Loader.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C444795  (server)    5/22/2008 12:15 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;MoreEvents
@@ -134,7 +134,7 @@
                     return false;
                 }
 
-                LoadLibrary(initializerType);
+                LoadLibrary(initializerType, false);
             } else {
                 // load namespaces:
                 try {
@@ -447,7 +447,7 @@
         #region IronRuby Libraries
 
         /// <exception cref="LoadError"></exception>
-        internal bool TryLoadStandardRubyLibraries() {
+        internal bool TryLoadBuiltins() {
             Type initializerType;
             try {
                 Assembly assembly = _executionContext.Context.DomainManager.Platform.LoadAssembly(GetIronRubyAssemblyLongName("IronRuby.Libraries"));
@@ -458,7 +458,7 @@
                 throw new LoadError(e.Message, e);
             }
 
-            LoadLibrary(initializerType);
+            LoadLibrary(initializerType, true);
             return true;
         }
 
@@ -472,7 +472,7 @@
         }
 
         /// <exception cref="LoadError"></exception>
-        private void LoadLibrary(Type/*!*/ initializerType) {
+        private void LoadLibrary(Type/*!*/ initializerType, bool builtin) {
             LibraryInitializer initializer;
             try {
                 initializer = Activator.CreateInstance(initializerType) as LibraryInitializer;
@@ -490,7 +490,7 @@
             }
 
             try {
-                initializer.LoadModules(_executionContext);
+                initializer.LoadModules(_executionContext, builtin);
             } catch (Exception e) {
                 throw new LoadError(e.Message, e);
             }
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyExecutionContext.cs;C444795
File: RubyExecutionContext.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyExecutionContext.cs;C444795  (server)    5/22/2008 11:01 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyExecutionContext.cs;MoreEvents
@@ -130,6 +130,10 @@
         private DynamicSite<RubyModule, SymbolId, object> _methodAddedCallbackSite;
         private DynamicSite<RubyModule, SymbolId, object> _methodRemovedCallbackSite;
         private DynamicSite<RubyModule, SymbolId, object> _methodUndefinedCallbackSite;
+        private DynamicSite<object, SymbolId, object> _singletonMethodAddedCallbackSite;
+        private DynamicSite<object, SymbolId, object> _singletonMethodRemovedCallbackSite;
+        private DynamicSite<object, SymbolId, object> _singletonMethodUndefinedCallbackSite;
+        private DynamicSite<RubyClass, RubyClass, object> _classInheritedCallbackSite;
 
         public Exception CurrentException {
             get { return _currentException; } 
@@ -244,7 +248,7 @@
             
             _loader = new Loader(this);
 
-            if (!_loader.TryLoadStandardRubyLibraries()) {
+            if (!_loader.TryLoadBuiltins()) {
                 Action<RubyModule> empty = delegate(RubyModule/*!*/ module) { };
                 RegisterPrimitives(empty, empty, empty, empty, empty, empty, empty, empty, empty, empty, empty);
             } else {
@@ -660,6 +664,7 @@
             return result;
         }
 
+        // triggers "inherited" event:
         public RubyClass/*!*/ DefineClass(RubyModule/*!*/ owner, SymbolId name, RubyClass/*!*/ superClass) {
             ContractUtils.RequiresNotNull(owner, "owner");
             ContractUtils.RequiresNotNull(superClass, "superClass");
@@ -670,6 +675,9 @@
             if (!name.IsEmpty) {
                 owner.SetConstant(name, result);
             }
+
+            ClassInherited(superClass, result);
+
             return result;
         }
 
@@ -706,12 +714,12 @@
         }
 
         internal RubyClass/*!*/ DefineLibraryClass(string name, Type/*!*/ type, Action<RubyModule> instanceTrait, Action<RubyModule> classTrait,
-            RubyClass super, RubyModule[]/*!*/ mixins, Delegate[] factories) {
+            RubyClass super, RubyModule[]/*!*/ mixins, Delegate[] factories, bool builtin) {
 
             Assert.NotNull(type);
 
+            RubyClass result;
             lock (ModuleCacheSyncRoot) {
-                RubyClass result;
                 if (TryGetClassNoLock(type, out result)) {
                     if (super != null && super != result.SuperClass) {
                         // TODO: better message
@@ -742,8 +750,13 @@
                 result.Factories = factories;
 
                 AddModuleToCacheNoLock(type, result);
-                return result;
             }
+
+            if (!builtin) {
+                ClassInherited(super, result);
+            }
+
+            return result;
         }
 
         #endregion
@@ -1233,6 +1246,14 @@
                 }
 
                 _methodAddedCallbackSite.Invoke(_context.EmptyContext, module, name);
+            } else {
+                if (!_singletonMethodAddedCallbackSite.IsInitialized) {
+                    _singletonMethodAddedCallbackSite.EnsureInitialized(InvokeMemberAction.Make(_context.Binder, Symbols.SingletonMethodAdded,
+                        new CallSignature(ArgumentKind.Instance, ArgumentKind.Simple)
+                    ));
+                }
+
+                _singletonMethodAddedCallbackSite.Invoke(_context.EmptyContext, ((RubyClass)module).SingletonClassOf, name);
             }
         }
 
@@ -1246,6 +1267,14 @@
                 }
 
                 _methodRemovedCallbackSite.Invoke(_context.EmptyContext, module, name);
+            } else {
+                if (!_singletonMethodRemovedCallbackSite.IsInitialized) {
+                    _singletonMethodRemovedCallbackSite.EnsureInitialized(InvokeMemberAction.Make(_context.Binder, Symbols.MethodRemoved,
+                        new CallSignature(ArgumentKind.Instance, ArgumentKind.Simple)
+                    ));
+                }
+
+                _singletonMethodRemovedCallbackSite.Invoke(_context.EmptyContext, ((RubyClass)module).SingletonClassOf, name);
             }
         }
 
@@ -1259,9 +1288,27 @@
                 }
 
                 _methodUndefinedCallbackSite.Invoke(_context.EmptyContext, module, name);
+            } else {
+                if (!_singletonMethodUndefinedCallbackSite.IsInitialized) {
+                    _singletonMethodUndefinedCallbackSite.EnsureInitialized(InvokeMemberAction.Make(_context.Binder, Symbols.MethodUndefined,
+                        new CallSignature(ArgumentKind.Instance, ArgumentKind.Simple)
+                    ));
+                }
+
+                _singletonMethodUndefinedCallbackSite.Invoke(_context.EmptyContext, ((RubyClass)module).SingletonClassOf, name);
             }
         }
 
+        private void ClassInherited(RubyClass/*!*/ superClass, RubyClass/*!*/ subClass) {
+            if (!_classInheritedCallbackSite.IsInitialized) {
+                _classInheritedCallbackSite.EnsureInitialized(InvokeMemberAction.Make(_context.Binder, Symbols.Inherited,
+                    new CallSignature(ArgumentKind.Instance, ArgumentKind.Simple)
+                ));
+            }
+
+            _classInheritedCallbackSite.Invoke(_context.EmptyContext, superClass, subClass);
+        }
+
         #endregion
     }
 }
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;C445606
File: RubyOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;C445606  (server)    5/22/2008 10:49 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;MoreEvents
@@ -265,8 +265,8 @@
             Assert.NotNull(scope, clrMethod);
 
             // closes block over self and context
-            RubyBlockInfo info = new RubyBlockInfo(clrMethod, self, scope, parameterCount, hasParamsArray, firstArgumentIsNestedLValue); 
-            Proc result = new Proc(ProcKind.Block, info);
+            RubyBlockInfo info = new RubyBlockInfo(clrMethod, parameterCount, hasParamsArray, firstArgumentIsNestedLValue);
+            Proc result = new Proc(ProcKind.Block, self, scope, info);
 
             result.Owner = runtimeFlowControl;
             return result;
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBlockInfo.cs;C438696
File: RubyBlockInfo.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBlockInfo.cs;C438696  (server)    5/22/2008 10:49 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBlockInfo.cs;MoreEvents
@@ -29,14 +29,6 @@
     using Ast = Microsoft.Scripting.Ast.Expression;
 
     internal sealed class RubyBlockInfo {
-        // Self object captured by the block definition, if any.
-        // Although we could load self from scope in Ruby defined blocks, we cannot do so when we don't have a scope.
-        private readonly object _self;
-
-        // Local scope inside the proc captured by the block definition;
-        // Null for block defined out of Ruby;
-        private readonly RubyScope _scope;
-
         private readonly Delegate/*!*/ _method;
         private readonly int _optionalParamCount;
         private readonly bool _hasParamsArray;
@@ -46,19 +38,14 @@
         public int OptionalParamCount { get { return _optionalParamCount; } }
         public bool HasParamsArray { get { return _hasParamsArray; } }
 
-        internal object Self { get { return _self; } }
-        internal RubyScope LocalScope { get { return _scope; } }
-
         // block:
-        internal RubyBlockInfo(Delegate/*!*/ method, object self, RubyScope scope, int parameterCount, bool hasParamsArray, bool firstArgumentIsNestedLValue) {
+        internal RubyBlockInfo(Delegate/*!*/ method, int parameterCount, bool hasParamsArray, bool firstArgumentIsNestedLValue) {
             Assert.NotNull(method);
             
             _method = method;
-            _self = self;
             _optionalParamCount = parameterCount;
             _hasParamsArray = hasParamsArray;
             _firstArgumentIsNestedLValue = firstArgumentIsNestedLValue;
-            _scope = scope;
         }
 
         private Expression/*!*/ AddWarning(Expression/*!*/ codeContextExpression, Expression/*!*/ expression) {
===================================================================
