@@ -1163,11 +1163,25 @@ public IRubyObject ungetbyte(ThreadContext context, IRubyObject arg) {
1163
1163
}
1164
1164
1165
1165
// MRI: strio_write
1166
- @ JRubyMethod (name = { "write" }, required = 1 )
1166
+ @ JRubyMethod (name = "write" )
1167
1167
public IRubyObject write (ThreadContext context , IRubyObject arg ) {
1168
- checkWritable ();
1168
+ Ruby runtime = context .runtime ;
1169
+ return RubyFixnum .newFixnum (runtime , stringIOWrite (context , runtime , arg ));
1170
+ }
1169
1171
1170
- final Ruby runtime = context .runtime ;
1172
+ @ JRubyMethod (name = "write" , required = 1 , rest = true )
1173
+ public IRubyObject write (ThreadContext context , IRubyObject [] args ) {
1174
+ Ruby runtime = context .runtime ;
1175
+ long len = 0 ;
1176
+ for (IRubyObject arg : args ) {
1177
+ len += stringIOWrite (context , runtime , arg );
1178
+ }
1179
+ return RubyFixnum .newFixnum (runtime , len );
1180
+ }
1181
+
1182
+ // MRI: strio_write
1183
+ private long stringIOWrite (ThreadContext context , Ruby runtime , IRubyObject arg ) {
1184
+ checkWritable ();
1171
1185
1172
1186
RubyString str = arg .asString ();
1173
1187
int len , olen ;
@@ -1184,7 +1198,7 @@ public IRubyObject write(ThreadContext context, IRubyObject arg) {
1184
1198
str = EncodingUtils .strConvEnc (context , str , encStr , enc );
1185
1199
}
1186
1200
len = str .size ();
1187
- if (len == 0 ) return RubyFixnum . zero ( runtime ) ;
1201
+ if (len == 0 ) return 0 ;
1188
1202
checkModifiable ();
1189
1203
olen = ptr .string .size ();
1190
1204
if ((ptr .flags & OpenFile .APPEND ) != 0 ) {
@@ -1202,7 +1216,7 @@ public IRubyObject write(ThreadContext context, IRubyObject arg) {
1202
1216
ptr .pos += len ;
1203
1217
}
1204
1218
1205
- return RubyFixnum . newFixnum ( runtime , len ) ;
1219
+ return len ;
1206
1220
}
1207
1221
1208
1222
@ JRubyMethod
0 commit comments