@@ -262,47 +262,59 @@ protected StringIO(Ruby runtime, RubyClass klass) {
262262 super (runtime , klass );
263263 }
264264
265- @ JRubyMethod (visibility = PRIVATE )
265+ @ JRubyMethod (visibility = PRIVATE , keywords = true )
266266 public IRubyObject initialize (ThreadContext context ) {
267267 if (ptr == null ) {
268268 ptr = new StringIOData ();
269269 }
270270
271271 // does not dispatch quite right and is not really necessary for us
272272 //Helpers.invokeSuper(context, this, metaClass, "initialize", IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
273- strioInit (context , 0 , null , null );
273+ strioInit (context , 0 , null , null , null );
274274 return this ;
275275 }
276276
277- @ JRubyMethod (visibility = PRIVATE )
277+ @ JRubyMethod (visibility = PRIVATE , keywords = true )
278278 public IRubyObject initialize (ThreadContext context , IRubyObject arg0 ) {
279279 if (ptr == null ) {
280280 ptr = new StringIOData ();
281281 }
282282
283283 // does not dispatch quite right and is not really necessary for us
284284 //Helpers.invokeSuper(context, this, metaClass, "initialize", IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
285- strioInit (context , 1 , arg0 , null );
285+ strioInit (context , 1 , arg0 , null , null );
286286 return this ;
287287 }
288288
289- @ JRubyMethod (visibility = PRIVATE )
289+ @ JRubyMethod (visibility = PRIVATE , keywords = true )
290290 public IRubyObject initialize (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 ) {
291291 if (ptr == null ) {
292292 ptr = new StringIOData ();
293293 }
294294
295295 // does not dispatch quite right and is not really necessary for us
296296 //Helpers.invokeSuper(context, this, metaClass, "initialize", IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
297- strioInit (context , 2 , arg0 , arg1 );
297+ strioInit (context , 2 , arg0 , arg1 , null );
298+ return this ;
299+ }
300+
301+ @ JRubyMethod (visibility = PRIVATE , keywords = true )
302+ public IRubyObject initialize (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 ) {
303+ if (ptr == null ) {
304+ ptr = new StringIOData ();
305+ }
306+
307+ // does not dispatch quite right and is not really necessary for us
308+ //Helpers.invokeSuper(context, this, metaClass, "initialize", IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
309+ strioInit (context , 3 , arg0 , arg1 , arg2 );
298310 return this ;
299311 }
300312
301313 // MRI: strio_init
302- private void strioInit (ThreadContext context , int argc , IRubyObject arg0 , IRubyObject arg1 ) {
314+ private void strioInit (ThreadContext context , int argc , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 ) {
303315 Ruby runtime = context .runtime ;
304316 IRubyObject string = context .nil ;
305- IRubyObject mode = context .nil ;
317+ IRubyObject vmode = context .nil ;
306318
307319 StringIOData ptr = this .ptr ;
308320
@@ -320,25 +332,34 @@ private void strioInit(ThreadContext context, int argc, IRubyObject arg0, IRubyO
320332 string = arg0 ;
321333 maybeOptions = ArgsUtil .getOptionsArg (runtime , arg1 );
322334 if (maybeOptions .isNil ()) {
323- mode = arg1 ;
335+ vmode = arg1 ;
336+ }
337+ break ;
338+ case 3 :
339+ string = arg0 ;
340+ vmode = arg1 ;
341+ maybeOptions = ArgsUtil .getOptionsArg (runtime , arg2 );
342+ if (maybeOptions .isNil ()) {
343+ throw context .runtime .newArgumentError (argc , 0 , 2 );
324344 }
325345 break ;
326346 }
327347 if (!maybeOptions .isNil ()) {
328348 argc --;
329349 }
330350 Object vmodeAndVpermP = VMODE_VPERM_TL .get ();
331- EncodingUtils .vmode (vmodeAndVpermP , mode );
351+ EncodingUtils .vmode (vmodeAndVpermP , vmode );
332352 IOEncodable .ConvConfig ioEncodable = new IOEncodable .ConvConfig ();
353+ int [] fmode = FMODE_TL .get ();
333354
334355 // switch to per-use oflags if it is ever used in the future
335- EncodingUtils .extractModeEncoding (context , ioEncodable , vmodeAndVpermP , maybeOptions , OFLAGS_UNUSED , FMODE_TL .get ());
356+ EncodingUtils .extractModeEncoding (context , ioEncodable , vmodeAndVpermP , maybeOptions , OFLAGS_UNUSED , fmode );
357+ ptr .flags = fmode [0 ];
358+ vmode = EncodingUtils .vmode (vmodeAndVpermP );
336359
337360 // clear shared vmodeVperm
338361 clearVmodeVperm (vmodeAndVpermP );
339362
340- ptr .flags = FMODE_TL .get ()[0 ];
341-
342363 if (!string .isNil ()) {
343364 string = string .convertToString ();
344365 } else if (argc == 0 ) {
@@ -350,7 +371,7 @@ private void strioInit(ThreadContext context, int argc, IRubyObject arg0, IRubyO
350371 throw runtime .newErrnoEACCESError ("read-only string" );
351372 }
352373 } else {
353- if (mode .isNil ()) {
374+ if (vmode .isNil ()) {
354375 ptr .flags |= OpenFile .WRITABLE ;
355376 }
356377 }
@@ -1257,15 +1278,15 @@ public IRubyObject readlines(ThreadContext context, IRubyObject[] args) {
12571278 }
12581279
12591280 // MRI: strio_reopen
1260- @ JRubyMethod (name = "reopen" )
1281+ @ JRubyMethod (name = "reopen" , keywords = true )
12611282 public IRubyObject reopen (ThreadContext context ) {
12621283 // reset the state
1263- strioInit (context , 0 , null , null );
1284+ strioInit (context , 0 , null , null , null );
12641285 return this ;
12651286 }
12661287
12671288 // MRI: strio_reopen
1268- @ JRubyMethod (name = "reopen" )
1289+ @ JRubyMethod (name = "reopen" , keywords = true )
12691290 public IRubyObject reopen (ThreadContext context , IRubyObject arg0 ) {
12701291 checkFrozen ();
12711292
@@ -1274,17 +1295,27 @@ public IRubyObject reopen(ThreadContext context, IRubyObject arg0) {
12741295 }
12751296
12761297 // reset the state
1277- strioInit (context , 1 , arg0 , null );
1298+ strioInit (context , 1 , arg0 , null , null );
12781299 return this ;
12791300 }
12801301
12811302 // MRI: strio_reopen
1282- @ JRubyMethod (name = "reopen" )
1303+ @ JRubyMethod (name = "reopen" , keywords = true )
12831304 public IRubyObject reopen (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 ) {
12841305 checkFrozen ();
12851306
12861307 // reset the state
1287- strioInit (context , 2 , arg0 , arg1 );
1308+ strioInit (context , 2 , arg0 , arg1 , null );
1309+ return this ;
1310+ }
1311+
1312+ // MRI: strio_reopen
1313+ @ JRubyMethod (name = "reopen" , keywords = true )
1314+ public IRubyObject reopen (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 ) {
1315+ checkFrozen ();
1316+
1317+ // reset the state
1318+ strioInit (context , 3 , arg0 , arg1 , arg2 );
12881319 return this ;
12891320 }
12901321
0 commit comments