Skip to content

Commit

Permalink
Document all IO instance write methods
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 2, 2021
1 parent 236f7ba commit 659d6db
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -1422,14 +1422,23 @@ private void checkInitialized() {
}
}

/** io_write_m
/**
* Ruby method IO#write(str), equivalent to io_write_m.
*
* @param context the current context
* @param str the string to write
*/
@JRubyMethod(name = "write", required = 1)
public IRubyObject write(ThreadContext context, IRubyObject str) {
return write(context, str, false);
}

/**
* Ruby method IO#write(str, ...), equivalent to io_write_m.
*
* @param context the current context
* @param args the strings to write
*/
@JRubyMethod(name = "write", rest = true)
public IRubyObject write(ThreadContext context, IRubyObject[] args) {
long acc = 0l;
Expand All @@ -1441,12 +1450,29 @@ public IRubyObject write(ThreadContext context, IRubyObject[] args) {
return RubyFixnum.newFixnum(context.runtime, acc);
}

/**
* Write a single byte to this IO's write target.
*
* @param context the current context
* @param ch the byte to write, as an int
* @return the count of bytes written
*/
public final IRubyObject write(ThreadContext context, int ch) {
RubyString str = RubyString.newStringShared(context.runtime, RubyInteger.singleCharByteList((byte) ch));
return write(context, str, false);
}

// io_write

/**
* Write the given range of bytes to this IO's write target.
*
* Equivalent to io_write.
*
* @param context the current context
* @param str the string to write
* @param nosync whether to write without syncing
* @return the count of bytes written
*/
public IRubyObject write(ThreadContext context, IRubyObject str, boolean nosync) {
Ruby runtime = context.runtime;
OpenFile fptr;
Expand Down Expand Up @@ -1480,12 +1506,37 @@ public IRubyObject write(ThreadContext context, IRubyObject str, boolean nosync)
return RubyFixnum.newFixnum(runtime, n);
}

// io_write_m with source bytes
/**
* Write the given range of bytes to this IO.
*
* Equivalent to io_write_m with source bytes and no digging out any wrapped write IO (bytes will be written to this
* IO.
*
* @param context the current context
* @param bytes the bytes to write
* @param start start offset for writing
* @param length length to write
* @param encoding encoding of the bytes (will not be verified)
* @return the count of bytes written
*/
public IRubyObject write(ThreadContext context, byte[] bytes, int start, int length, Encoding encoding) {
return write(context, bytes, start, length, encoding, false);
}

// io_write with source bytes
/**
* Write the given range of bytes to this IO.
*
* Equivalent to io_write with source bytes and no digging out any wrapped write IO (bytes will be written to this
* IO.
*
* @param context the current context
* @param bytes the bytes to write
* @param start start offset for writing
* @param length length to write
* @param encoding encoding of the bytes (will not be verified)
* @param nosync whether to write without syncing
* @return the count of bytes written
*/
public IRubyObject write(ThreadContext context, byte[] bytes, int start, int length, Encoding encoding, boolean nosync) {
Ruby runtime = context.runtime;
OpenFile fptr;
Expand Down

0 comments on commit 659d6db

Please sign in to comment.