* variable.c (rb_const_defined_0): look up constants in Object as
  well.

* test/ruby/test_defined.rb (TestDefined::test_defined): test for
  constants.

Index: variable.c
===================================================================
RCS file: /cvs/ruby/src/ruby/variable.c,v
retrieving revision 1.104
diff -u -2 -p -r1.104 variable.c
--- variable.c	1 Oct 2003 16:06:19 -0000	1.104
+++ variable.c	1 Oct 2003 16:49:32 -0000
@@ -1431,10 +1431,10 @@ rb_const_defined_0(klass, id, exclude, r
     int exclude, recurse;
 {
-    VALUE tmp = klass, value;
+    VALUE value, tmp;
+    int mod_retry = 0;
 
+    tmp = klass;
+  retry:
     while (tmp) {
-	if (tmp == rb_cObject && klass != rb_cObject) {
-	    break;
-	}
 	if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl, id, &value)) {
 	    if (value == Qundef && NIL_P(autoload_file(klass, id)))
@@ -1445,6 +1445,8 @@ rb_const_defined_0(klass, id, exclude, r
 	tmp = RCLASS(tmp)->super;
     }
-    if (!exclude && BUILTIN_TYPE(klass) == T_MODULE) {
-	return rb_const_defined(rb_cObject, id);
+    if (!exclude && !mod_retry && BUILTIN_TYPE(klass) == T_MODULE) {
+	mod_retry = 1;
+	tmp = rb_cObject;
+	goto retry;
     }
     return Qfalse;
Index: test/ruby/test_defined.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/test/ruby/test_defined.rb,v
retrieving revision 1.3
diff -u -2 -p -r1.3 test_defined.rb
--- test/ruby/test_defined.rb	5 Sep 2003 15:15:43 -0000	1.3
+++ test/ruby/test_defined.rb	1 Oct 2003 16:56:11 -0000
@@ -25,8 +25,11 @@ class TestDefined < Test::Unit::TestCase
     assert_equal('global-variable', defined?($x))# returns description
 
+    assert_nil(defined?(foo))		# undefined
     foo=5
     assert(defined?(foo))		# local variable
 
-    assert(defined?(::Array))		# constant	!! Array -> ::Array
+    assert(defined?(Array))		# constant
+    assert(defined?(::Array))		# toplevel constant
+    assert(defined?(File::Constants))	# nested constant
     assert(defined?(Object.new))	# method
     assert(!defined?(Object.print))	# private method
