--A9Iv2k6ay/+eYwwO4ow
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

I wrote a patch to add a Module#const_missing method like the 
Object#method_missing method to Ruby.

Regards
	Jan Arne Petersen

--A9Iv2k6ay/+eYwwO4ow
Content-Disposition: attachment; filename=variable.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=variable.diff; charset=ISO-8859-15

Index: variable.c
===================================================================
RCS file: /src/ruby/variable.c,v
retrieving revision 1.69
diff -u -r1.69 variable.c
--- variable.c	2002/09/05 09:42:56	1.69
+++ variable.c	2002/09/05 23:41:24
@@ -1177,10 +1177,8 @@
     }
 
     /* Uninitialized constant */
-    if (klass && klass != rb_cObject) {
-	rb_name_error(id, "uninitialized constant %s at %s",
-		      rb_id2name(id),
-		      RSTRING(rb_class_path(klass))->ptr);
+    if (klass) {
+	return rb_funcall(klass, rb_intern("const_missing"), 1, ID2SYM(id));
     }
     else { /* global_uninitialized */
 	rb_name_error(id, "uninitialized constant %s",rb_id2name(id));

--A9Iv2k6ay/+eYwwO4ow
Content-Disposition: attachment; filename=eval.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=eval.diff; charset=ISO-8859-15

Index: eval.c
===================================================================
RCS file: /src/ruby/eval.c,v
retrieving revision 1.324
diff -u -r1.324 eval.c
--- eval.c	2002/09/05 04:15:50	1.324
+++ eval.c	2002/09/05 23:41:14
@@ -4391,6 +4391,27 @@
     return rb_funcall2(obj, missing, argc+1, nargv);
 }
 
+VALUE
+rb_mod_const_missing(klass, name)
+	    VALUE klass, name;
+{
+    ID id = rb_to_id(name);
+	      
+    PUSH_FRAME();               /* fake frame */
+    *ruby_frame = *_frame.prev->prev;
+    if (klass && klass != rb_cObject) {
+	rb_name_error(id, "uninitialized constant %s at %s",
+		      rb_id2name(id),
+		      RSTRING(rb_class_path(klass))->ptr);
+    }
+    else { /* global_uninitialized */
+	rb_name_error(id, "uninitialized constant %s",rb_id2name(id));
+    }   
+    POP_FRAME();
+
+    return Qnil;                /* not reached */
+}
+
 static VALUE
 call_cfunc(func, recv, len, argc, argv)
     VALUE (*func)();
@@ -6146,6 +6167,8 @@
 
     rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
     rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, 0);
+
+    rb_define_method(rb_cModule, "const_missing", rb_mod_const_missing, 1);
 
     rb_define_singleton_method(ruby_top_self, "include", top_include, -1);
     rb_define_singleton_method(ruby_top_self, "public", top_public, -1);

--A9Iv2k6ay/+eYwwO4ow--