Skip to content

Commit be3bd17

Browse files
committedMar 27, 2018
StringIO#write takes multiple arguments. #4876
1 parent ab440ad commit be3bd17

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed
 

‎core/src/main/java/org/jruby/ext/stringio/StringIO.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,25 @@ public IRubyObject ungetbyte(ThreadContext context, IRubyObject arg) {
11631163
}
11641164

11651165
// MRI: strio_write
1166-
@JRubyMethod(name = {"write"}, required = 1)
1166+
@JRubyMethod(name = "write")
11671167
public IRubyObject write(ThreadContext context, IRubyObject arg) {
1168-
checkWritable();
1168+
Ruby runtime = context.runtime;
1169+
return RubyFixnum.newFixnum(runtime, stringIOWrite(context, runtime, arg));
1170+
}
11691171

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();
11711185

11721186
RubyString str = arg.asString();
11731187
int len, olen;
@@ -1184,7 +1198,7 @@ public IRubyObject write(ThreadContext context, IRubyObject arg) {
11841198
str = EncodingUtils.strConvEnc(context, str, encStr, enc);
11851199
}
11861200
len = str.size();
1187-
if (len == 0) return RubyFixnum.zero(runtime);
1201+
if (len == 0) return 0;
11881202
checkModifiable();
11891203
olen = ptr.string.size();
11901204
if ((ptr.flags & OpenFile.APPEND) != 0) {
@@ -1202,7 +1216,7 @@ public IRubyObject write(ThreadContext context, IRubyObject arg) {
12021216
ptr.pos += len;
12031217
}
12041218

1205-
return RubyFixnum.newFixnum(runtime, len);
1219+
return len;
12061220
}
12071221

12081222
@JRubyMethod

0 commit comments

Comments
 (0)
Please sign in to comment.