@@ -4625,6 +4625,7 @@ private boolean constDefined(ThreadContext context, IRubyObject name, boolean in
4625
4625
int patternIndex ;
4626
4626
int index = 0 ;
4627
4627
RubyModule mod = this ;
4628
+ boolean includeObject = true ;
4628
4629
4629
4630
if (value .startsWith (pattern )) {
4630
4631
mod = objectClass (context );
@@ -4658,6 +4659,7 @@ private boolean constDefined(ThreadContext context, IRubyObject name, boolean in
4658
4659
4659
4660
mod = (RubyModule ) obj ;
4660
4661
currentOffset = patternIndex + pattern .getRealSize ();
4662
+ includeObject = false ;
4661
4663
}
4662
4664
4663
4665
if (mod == null ) mod = this ; // Bare 'Foo'
@@ -4666,7 +4668,7 @@ private boolean constDefined(ThreadContext context, IRubyObject name, boolean in
4666
4668
4667
4669
String id = RubySymbol .newConstantSymbol (context , fullName , lastSegment ).idString ();
4668
4670
4669
- return mod .getConstantSkipAutoload (context , id , inherit , inherit ) != null ;
4671
+ return mod .getConstantSkipAutoload (context , id , inherit , inherit && includeObject , false ) != null ;
4670
4672
}
4671
4673
4672
4674
// MRI: rb_mod_const_get
@@ -5370,10 +5372,10 @@ public IRubyObject getConstantNoConstMissing(String name, boolean inherit, boole
5370
5372
}
5371
5373
5372
5374
public IRubyObject getConstantNoConstMissing (ThreadContext context , String name , boolean inherit , boolean includeObject ) {
5373
- IRubyObject constant = iterateConstantNoConstMissing (context , name , this , inherit , true );
5375
+ IRubyObject constant = iterateConstantNoConstMissing (context , name , this , inherit , true , true );
5374
5376
5375
5377
if (constant == null && !isClass () && includeObject ) {
5376
- constant = iterateConstantNoConstMissing (context , name , objectClass (context ), inherit , true );
5378
+ constant = iterateConstantNoConstMissing (context , name , objectClass (context ), inherit , true , true );
5377
5379
}
5378
5380
5379
5381
return constant ;
@@ -5385,20 +5387,20 @@ public final IRubyObject getConstantNoConstMissingSkipAutoload(String name) {
5385
5387
}
5386
5388
5387
5389
public final IRubyObject getConstantNoConstMissingSkipAutoload (ThreadContext context , String name ) {
5388
- return getConstantSkipAutoload (context , name , true , true );
5390
+ return getConstantSkipAutoload (context , name , true , true , true );
5389
5391
}
5390
5392
5391
5393
@ Deprecated
5392
5394
public IRubyObject getConstantNoConstMissingSKipAutoload (String name ) {
5393
- return getConstantSkipAutoload (getCurrentContext (), name , true , true );
5395
+ return getConstantSkipAutoload (getCurrentContext (), name , true , true , true );
5394
5396
}
5395
5397
5396
5398
// returns null for autoloads that have failed
5397
- private IRubyObject getConstantSkipAutoload (ThreadContext context , String name , boolean inherit , boolean includeObject ) {
5398
- IRubyObject constant = iterateConstantNoConstMissing (context , name , this , inherit , false );
5399
+ private IRubyObject getConstantSkipAutoload (ThreadContext context , String name , boolean inherit , boolean searchObject , boolean inheritObject ) {
5400
+ IRubyObject constant = iterateConstantNoConstMissing (context , name , this , inherit , false , inheritObject );
5399
5401
5400
- if (constant == null && !isClass () && includeObject ) {
5401
- constant = iterateConstantNoConstMissing (context , name , objectClass ( context ) , inherit , false );
5402
+ if (constant == null && !isClass () && searchObject ) {
5403
+ constant = iterateConstantNoConstMissing (context , name , getRuntime (). getObject () , inherit , false , true );
5402
5404
}
5403
5405
5404
5406
return constant ;
@@ -5423,7 +5425,8 @@ private static SourceLocation iterateConstantEntryNoConstMissing(String name, Ru
5423
5425
}
5424
5426
5425
5427
private static IRubyObject iterateConstantNoConstMissing (ThreadContext context , String name ,
5426
- RubyModule init , boolean inherit , boolean loadConstant ) {
5428
+ RubyModule init , boolean inherit , boolean loadConstant , boolean includeObject ) {
5429
+ RubyClass objectClass = init .getRuntime ().getObject ();
5427
5430
for (RubyModule mod = init ; mod != null ; mod = mod .getSuperClass ()) {
5428
5431
IRubyObject value = loadConstant ?
5429
5432
mod .getConstantWithAutoload (context , name , null , true ) :
@@ -5434,6 +5437,8 @@ private static IRubyObject iterateConstantNoConstMissing(ThreadContext context,
5434
5437
if (value != null ) return value ;
5435
5438
5436
5439
if (!inherit ) break ;
5440
+
5441
+ if (!includeObject && mod .getSuperClass () == objectClass ) break ;
5437
5442
}
5438
5443
return null ;
5439
5444
}
0 commit comments