@@ -150,17 +150,20 @@ public IRubyObject to_str(ThreadContext context) {
150150 if (klass .isSingleton ()) {
151151 separator = newString (context , "" );
152152 if (object == runtime .getTopSelf ()) {
153- classTmp = newString (context , "main" );
153+ className = newString (context , "main" );
154154 } else {
155- classTmp = object .anyToString ();
155+ className = ( RubyString ) object .anyToString ();
156156 }
157157 } else {
158158 separator = newString (context , "an instance of " );
159159 classTmp = klass .getRealClass ();
160+ className = getNameOrInspect (context , classTmp );
160161 }
162+ } else {
163+ className = getNameOrInspect (context , classTmp );
161164 }
162165
163- className = getNameOrInspect ( context , classTmp );
166+
164167 }
165168
166169 RubyArray arr = RubyArray .newArray (runtime , this .name , description , separator , className );
@@ -239,21 +242,20 @@ protected RaiseException constructThrowable(String message) {
239242
240243 @ JRubyMethod (name = "exception" , meta = true )
241244 public static IRubyObject exception (ThreadContext context , IRubyObject recv ) {
242- return newNameError (recv , NULL_ARRAY );
245+ return newNameError (context , recv , NULL_ARRAY );
243246 }
244247
245248 @ JRubyMethod (name = "exception" , meta = true )
246249 public static RubyException exception (ThreadContext context , IRubyObject recv , IRubyObject message ) {
247- return newNameError (recv , new IRubyObject [] { message });
250+ return newNameError (context , recv , new IRubyObject [] { message });
248251 }
249252
250253 @ JRubyMethod (name = "exception" , meta = true )
251254 public static RubyException exception (ThreadContext context , IRubyObject recv , IRubyObject message , IRubyObject name ) {
252- return newNameError (recv , message , name , false );
255+ return newNameError (context , recv , message , name , false );
253256 }
254257
255- private static RubyException newNameError (IRubyObject recv , IRubyObject [] args ) {
256- var context = recv .getRuntime ().getCurrentContext ();
258+ private static RubyException newNameError (ThreadContext context , IRubyObject recv , IRubyObject [] args ) {
257259 final RubyClass klass = (RubyClass ) recv ;
258260 RubyException newError = (RubyException ) klass .allocate (context );
259261
@@ -262,8 +264,7 @@ private static RubyException newNameError(IRubyObject recv, IRubyObject[] args)
262264 return newError ;
263265 }
264266
265- static RubyException newNameError (IRubyObject recv , IRubyObject message , IRubyObject name , boolean privateCall ) {
266- var context = recv .getRuntime ().getCurrentContext ();
267+ static RubyException newNameError (ThreadContext context , IRubyObject recv , IRubyObject message , IRubyObject name , boolean privateCall ) {
267268 final RubyClass klass = (RubyClass ) recv ;
268269 RubyNameError newError = (RubyNameError ) klass .allocate (context );
269270
0 commit comments