@@ -1271,7 +1271,7 @@ public void prependModule(ThreadContext context, RubyModule module) {
12711271
12721272 if (this .isModule ()) {
12731273 boolean doPrepend = true ;
1274- synchronized (getRuntime () .getHierarchyLock ()) {
1274+ synchronized (context . runtime .getHierarchyLock ()) {
12751275 for (RubyClass includeClass : includingHierarchies ) {
12761276 RubyClass checkClass = includeClass ;
12771277 while (checkClass != null ) {
@@ -1290,7 +1290,7 @@ public void prependModule(ThreadContext context, RubyModule module) {
12901290
12911291 invalidateCoreClasses (context );
12921292 invalidateCacheDescendants (context );
1293- invalidateConstantCacheForModuleInclusion (module );
1293+ invalidateConstantCacheForModuleInclusion (context , module );
12941294 }
12951295 }
12961296
@@ -1328,7 +1328,7 @@ public synchronized void includeModule(ThreadContext context, IRubyObject arg) {
13281328
13291329 if (this .isModule ()) {
13301330 boolean doInclude = true ;
1331- synchronized (getRuntime () .getHierarchyLock ()) {
1331+ synchronized (context . runtime .getHierarchyLock ()) {
13321332 for (RubyClass includeClass : includingHierarchies ) {
13331333 RubyClass checkClass = includeClass ;
13341334 while (checkClass != null ) {
@@ -1347,7 +1347,7 @@ public synchronized void includeModule(ThreadContext context, IRubyObject arg) {
13471347
13481348 invalidateCoreClasses (context );
13491349 invalidateCacheDescendants (context );
1350- invalidateConstantCacheForModuleInclusion (module );
1350+ invalidateConstantCacheForModuleInclusion (context , module );
13511351 }
13521352
13531353 /**
@@ -2104,12 +2104,12 @@ private CacheEntry cacheHit(String name) {
21042104 return null ;
21052105 }
21062106
2107- private void invalidateConstantCacheForModuleInclusion (RubyModule module ) {
2107+ private void invalidateConstantCacheForModuleInclusion (ThreadContext context , RubyModule module ) {
21082108 Map <String , Invalidator > invalidators = null ;
21092109 for (RubyModule mod : gatherModules (module )) {
21102110 for (String name : mod .getConstantMap ().keySet ()) {
21112111 if (invalidators == null ) invalidators = new HashMap <>();
2112- invalidators .put (name , getRuntime () .getConstantInvalidator (name ));
2112+ invalidators .put (name , context . runtime .getConstantInvalidator (name ));
21132113 }
21142114 }
21152115 if (invalidators != null ) {
@@ -2381,7 +2381,7 @@ protected void invalidateConstantCache(ThreadContext context, String constantNam
23812381 @ Deprecated (since = "10.0" )
23822382 protected void invalidateConstantCaches (Set <String > constantNames ) {
23832383 if (constantNames .size () > 0 ) {
2384- Ruby runtime = getRuntime () ;
2384+ Ruby runtime = getCurrentContext (). runtime ;
23852385
23862386 List <Invalidator > constantInvalidators = new ArrayList <>(constantNames .size ());
23872387 for (String name : constantNames ) {
@@ -2787,20 +2787,24 @@ public boolean isMethodBound(String name, boolean checkVisibility, boolean check
27872787 return checkRespondTo ? respondsToMethod (name , checkVisibility ): isMethodBound (name , checkVisibility );
27882788 }
27892789
2790+ @ Deprecated (since = "10.0" )
27902791 public final IRubyObject newMethod (IRubyObject receiver , String methodName , boolean bound , Visibility visibility ) {
2791- return newMethod (receiver , methodName , bound , visibility , false , true );
2792+ return newMethod (getCurrentContext (), receiver , methodName , null , bound , visibility , false , true );
27922793 }
27932794
2795+ @ Deprecated (since = "10.0" )
27942796 public final IRubyObject newMethod (IRubyObject receiver , String methodName , StaticScope refinedScope , boolean bound , Visibility visibility ) {
2795- return newMethod (receiver , methodName , refinedScope , bound , visibility , false , true );
2797+ return newMethod (getCurrentContext (), receiver , methodName , refinedScope , bound , visibility , false , true );
27962798 }
27972799
2800+ @ Deprecated (since = "10.0" )
27982801 public final IRubyObject newMethod (IRubyObject receiver , final String methodName , boolean bound , Visibility visibility , boolean respondToMissing ) {
2799- return newMethod (receiver , methodName , bound , visibility , respondToMissing , true );
2802+ return newMethod (getCurrentContext (), receiver , methodName , null , bound , visibility , respondToMissing , true );
28002803 }
28012804
2805+ @ Deprecated (since = "10.0" )
28022806 public final IRubyObject newMethod (IRubyObject receiver , final String methodName , StaticScope scope , boolean bound , Visibility visibility , boolean respondToMissing ) {
2803- return newMethod (receiver , methodName , scope , bound , visibility , respondToMissing , true );
2807+ return newMethod (getCurrentContext (), receiver , methodName , scope , bound , visibility , respondToMissing , true );
28042808 }
28052809
28062810 public static class RespondToMissingMethod extends JavaMethod .JavaMethodNBlock {
@@ -2832,12 +2836,20 @@ public int hashCode() {
28322836
28332837 }
28342838
2835- public IRubyObject newMethod (IRubyObject receiver , final String methodName , boolean bound , Visibility visibility , boolean respondToMissing , boolean priv ) {
2836- return newMethod (receiver , methodName , null , bound , visibility , respondToMissing , priv );
2839+ @ Deprecated (since = "10.0" )
2840+ public IRubyObject newMethod (IRubyObject receiver , final String methodName , boolean bound , Visibility visibility ,
2841+ boolean respondToMissing , boolean priv ) {
2842+ return newMethod (getCurrentContext (), receiver , methodName , null , bound , visibility , respondToMissing , priv );
28372843 }
28382844
2839- public IRubyObject newMethod (IRubyObject receiver , final String methodName , StaticScope scope , boolean bound , Visibility visibility , boolean respondToMissing , boolean priv ) {
2840- var context = getRuntime ().getCurrentContext ();
2845+ @ Deprecated (since = "10.0" )
2846+ public IRubyObject newMethod (IRubyObject receiver , final String methodName , StaticScope scope , boolean bound ,
2847+ Visibility visibility , boolean respondToMissing , boolean priv ) {
2848+ return newMethod (getCurrentContext (), receiver , methodName , scope , bound , visibility , respondToMissing , priv );
2849+ }
2850+
2851+ protected IRubyObject newMethod (ThreadContext context , IRubyObject receiver , final String methodName , StaticScope scope ,
2852+ boolean bound , Visibility visibility , boolean respondToMissing , boolean priv ) {
28412853 CacheEntry entry = scope == null ? searchWithCache (methodName ) : searchWithRefinements (methodName , scope );
28422854
28432855 if (entry .method .isUndefined () || visibility != null && entry .method .getVisibility () != visibility ) {
@@ -2978,8 +2990,12 @@ public IRubyObject name(ThreadContext context) {
29782990 return getBaseName () == null ? context .nil : rubyName (context );
29792991 }
29802992
2993+ @ Deprecated (since = "10.0" )
29812994 protected final IRubyObject cloneMethods (RubyModule clone ) {
2982- Ruby runtime = getRuntime ();
2995+ return cloneMethods (getCurrentContext (), clone );
2996+ }
2997+
2998+ protected final IRubyObject cloneMethods (ThreadContext context , RubyModule clone ) {
29832999 RubyModule realType = this .getOrigin ();
29843000 for (Map .Entry <String , DynamicMethod > entry : getMethods ().entrySet ()) {
29853001 DynamicMethod method = entry .getValue ();
@@ -2991,7 +3007,7 @@ protected final IRubyObject cloneMethods(RubyModule clone) {
29913007 // TODO: Make DynamicMethod immutable
29923008 DynamicMethod clonedMethod = method .dup ();
29933009 clonedMethod .setImplementationClass (clone );
2994- clone .putMethod (runtime , entry .getKey (), clonedMethod );
3010+ clone .putMethod (context . runtime , entry .getKey (), clonedMethod );
29953011 }
29963012 }
29973013
@@ -3010,13 +3026,13 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject original)
30103026 RubyModule originalModule = (RubyModule )original ;
30113027
30123028 if (!getMetaClass ().isSingleton ()) {
3013- setMetaClass (originalModule .getSingletonClassCloneAndAttach (this ));
3029+ setMetaClass (originalModule .getSingletonClassCloneAndAttach (context , this ));
30143030 }
30153031 superClass (originalModule .superClass ());
30163032 if (originalModule .hasVariables ()) syncVariables (originalModule );
30173033 syncConstants (originalModule );
30183034
3019- originalModule .cloneMethods (this );
3035+ originalModule .cloneMethods (context , this );
30203036
30213037 this .javaProxy = originalModule .javaProxy ;
30223038
@@ -3492,18 +3508,28 @@ public IRubyObject attr_accessor(ThreadContext context, IRubyObject[] args) {
34923508 * @param not if true only find methods not matching supplied visibility
34933509 * @return a RubyArray of instance method names
34943510 */
3511+ @ Deprecated (since = "10.0" )
34953512 private RubyArray instance_methods (IRubyObject [] args , Visibility visibility , boolean not ) {
34963513 boolean includeSuper = args .length > 0 ? args [0 ].isTrue () : true ;
3497- return instanceMethods (visibility , includeSuper , true , not );
3514+ return instanceMethods (getCurrentContext (), visibility , includeSuper , true , not );
34983515 }
34993516
3517+ @ Deprecated (since = "10.0" )
35003518 public RubyArray instanceMethods (IRubyObject [] args , Visibility visibility , boolean obj , boolean not ) {
3519+ return instanceMethods (getCurrentContext (), args , visibility , obj , not );
3520+ }
3521+
3522+ public RubyArray instanceMethods (ThreadContext context , IRubyObject [] args , Visibility visibility , boolean obj , boolean not ) {
35013523 boolean includeSuper = args .length > 0 ? args [0 ].isTrue () : true ;
3502- return instanceMethods (visibility , includeSuper , obj , not );
3524+ return instanceMethods (context , visibility , includeSuper , obj , not );
35033525 }
35043526
3527+ @ Deprecated (since = "10.0" )
35053528 public RubyArray instanceMethods (Visibility visibility , boolean includeSuper , boolean obj , boolean not ) {
3506- var context = getRuntime ().getCurrentContext ();
3529+ return instanceMethods (getCurrentContext (), visibility , includeSuper , obj , not );
3530+ }
3531+
3532+ private RubyArray instanceMethods (ThreadContext context , Visibility visibility , boolean includeSuper , boolean obj , boolean not ) {
35073533 var ary = newArray (context );
35083534
35093535 populateInstanceMethodNames (context , new HashSet <>(), ary , visibility , obj , not , includeSuper );
@@ -3570,7 +3596,7 @@ public RubyArray<?> instance_methods(IRubyObject[] args) {
35703596 public RubyArray instance_methods (ThreadContext context , IRubyObject [] args ) {
35713597 Arity .checkArgumentCount (context , args , 0 , 1 );
35723598
3573- return instanceMethods (args , PRIVATE , false , true );
3599+ return instanceMethods (context , args , PRIVATE , false , true );
35743600 }
35753601
35763602 @ Deprecated
@@ -3587,17 +3613,18 @@ public RubyArray<?> public_instance_methods(IRubyObject[] args) {
35873613 public RubyArray public_instance_methods (ThreadContext context , IRubyObject [] args ) {
35883614 Arity .checkArgumentCount (context , args , 0 , 1 );
35893615
3590- return instanceMethods (args , PUBLIC , false , false );
3616+ return instanceMethods (context , args , PUBLIC , false , false );
35913617 }
35923618
35933619 @ JRubyMethod (name = "instance_method" , reads = SCOPE )
35943620 public IRubyObject instance_method (ThreadContext context , IRubyObject symbol ) {
3595- return newMethod (null , checkID (context , symbol ).idString (), context .getCurrentStaticScope (), false , null );
3621+ return newMethod (context , null , checkID (context , symbol ).idString (), context .getCurrentStaticScope (),
3622+ false , null , false , true );
35963623 }
35973624
35983625 @ Deprecated (since = "10.0" )
35993626 public IRubyObject instance_method (IRubyObject symbol ) {
3600- return newMethod ( null , checkID ( getCurrentContext (), symbol ). idString (), false , null );
3627+ return instance_method ( getCurrentContext (), symbol );
36013628 }
36023629
36033630 @ Deprecated (since = "10.0" )
@@ -3607,7 +3634,7 @@ public IRubyObject public_instance_method(IRubyObject symbol) {
36073634
36083635 @ JRubyMethod (name = "public_instance_method" )
36093636 public IRubyObject public_instance_method (ThreadContext context , IRubyObject symbol ) {
3610- return newMethod (null , checkID (context , symbol ).idString (), false , PUBLIC );
3637+ return newMethod (context , null , checkID (context , symbol ).idString (), null , false , PUBLIC , false , true );
36113638 }
36123639
36133640 @ Deprecated
@@ -3622,7 +3649,7 @@ public RubyArray protected_instance_methods(IRubyObject[] args) {
36223649 public RubyArray protected_instance_methods (ThreadContext context , IRubyObject [] args ) {
36233650 Arity .checkArgumentCount (context , args , 0 , 1 );
36243651
3625- return instanceMethods (args , PROTECTED , false , false );
3652+ return instanceMethods (context , args , PROTECTED , false , false );
36263653 }
36273654
36283655 @ Deprecated
@@ -3637,7 +3664,7 @@ public RubyArray private_instance_methods(IRubyObject[] args) {
36373664 public RubyArray private_instance_methods (ThreadContext context , IRubyObject [] args ) {
36383665 Arity .checkArgumentCount (context , args , 0 , 1 );
36393666
3640- return instanceMethods (args , PRIVATE , false , false );
3667+ return instanceMethods (context , args , PRIVATE , false , false );
36413668 }
36423669
36433670 @ JRubyMethod (name = "undefined_instance_methods" )
@@ -5294,7 +5321,7 @@ private IRubyObject getConstantSkipAutoload(ThreadContext context, String name,
52945321 IRubyObject constant = iterateConstantNoConstMissing (context , name , this , inherit , false );
52955322
52965323 if (constant == null && !isClass () && includeObject ) {
5297- constant = iterateConstantNoConstMissing (context , name , getRuntime (). getObject ( ), inherit , false );
5324+ constant = iterateConstantNoConstMissing (context , name , objectClass ( context ), inherit , false );
52985325 }
52995326
53005327 return constant ;
@@ -5962,10 +5989,9 @@ private String validateClassVariable(ThreadContext context, String name) {
59625989
59635990 @ Deprecated (since = "10.0" )
59645991 protected final String validateClassVariable (IRubyObject nameObj , String name ) {
5965- if (IdUtil .isValidClassVariableName (name )) {
5966- return name ;
5967- }
5968- throw getRuntime ().newNameError ("'%1$s' is not allowed as a class variable name" , this , nameObj );
5992+ if (IdUtil .isValidClassVariableName (name )) return name ;
5993+
5994+ throw getCurrentContext ().runtime .newNameError ("'%1$s' is not allowed as a class variable name" , this , nameObj );
59695995 }
59705996
59715997 @ Deprecated (since = "10.0" )
0 commit comments