From b5c9269604f6dd816692b0c00b6a205f655e646a Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sat, 15 Nov 2025 07:47:46 -0600 Subject: [PATCH 1/3] [ruby/stringio] [DOC] Tweaks for StringIO#each_line (https://github.com/ruby/stringio/pull/165) Adds to "Position": pos inside a character. Makes a couple of minor corrections. --------- https://github.com/ruby/stringio/commit/ff332abafa Co-authored-by: Sutou Kouhei --- ext/stringio/stringio.c | 164 +--------------------------------------- 1 file changed, 1 insertion(+), 163 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 17be72f71a8cb6..e34be661cb8b12 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1473,170 +1473,8 @@ strio_readline(int argc, VALUE *argv, VALUE self) * each_line(limit, chomp: false) {|line| ... } -> self * each_line(sep, limit, chomp: false) {|line| ... } -> self * - * With a block given calls the block with each remaining line (see "Position" below) in the stream; - * returns `self`. + * :include: stringio/each_line.md * - * Leaves stream position as end-of-stream. - * - * **No Arguments** - * - * With no arguments given, - * reads lines using the default record separator global variable `$/`, whose initial value is `"\n"`. - * - * ``` - * strio = StringIO.new(TEXT) - * strio.each_line {|line| p line } - * strio.eof? # => true - * ``` - * - * Output: - * - * ``` - * "First line\n" - * "Second line\n" - * "\n" - * "Fourth line\n" - * "Fifth line\n" - * ``` - * - * **Argument `sep`** - * - * With only string argument `sep` given, - * reads lines using that string as the record separator: - * - * ``` - * strio = StringIO.new(TEXT) - * strio.each_line(' ') {|line| p line } - * ``` - * - * Output: - * - * ``` - * "First " - * "line\nSecond " - * "line\n\nFourth " - * "line\nFifth " - * "line\n" - * ``` - * - * **Argument `limit`** - * - * With only integer argument `limit` given, - * reads lines using the default record separator global variable `$/`, whose initial value is `"\n"`; - * also limits the size (in characters) of each line to the given limit: - * - * ``` - * strio = StringIO.new(TEXT) - * strio.each_line(10) {|line| p line } - * ``` - * - * Output: - * - * ``` - * "First line" - * "\n" - * "Second lin" - * "e\n" - * "\n" - * "Fourth lin" - * "e\n" - * "Fifth line" - * "\n" - * ``` - * **Arguments `sep` and `limit`** - * - * With arguments `sep` and `limit` both given, - * honors both: - * - * ``` - * strio = StringIO.new(TEXT) - * strio.each_line(' ', 10) {|line| p line } - * ``` - * - * Output: - * - * ``` - * "First " - * "line\nSecon" - * "d " - * "line\n\nFour" - * "th " - * "line\nFifth" - * " " - * "line\n" - * ``` - * - * **Position** - * - * As stated above, method `each` _remaining_ line in the stream. - * - * In the examples above each `strio` object starts with its position at beginning-of-stream; - * but in other cases the position may be anywhere (see StringIO#pos): - * - * ``` - * strio = StringIO.new(TEXT) - * strio.pos = 30 # Set stream position to character 30. - * strio.each_line {|line| p line } - * ``` - * - * Output: - * - * ``` - * " line\n" - * "Fifth line\n" - * ``` - * - * **Special Record Separators** - * - * Like some methds in class `IO`, StringIO.each honors two special record separators; - * see {Special Line Separators}[rdoc-ref:IO@Special+Line+Separator+Values]. - * - * ``` - * strio = StringIO.new(TEXT) - * strio.each_line('') {|line| p line } # Read as paragraphs (separated by blank lines). - * ``` - * - * Output: - * - * ``` - * "First line\nSecond line\n\n" - * "Fourth line\nFifth line\n" - * ``` - * - * ``` - * strio = StringIO.new(TEXT) - * strio.each_line(nil) {|line| p line } # "Slurp"; read it all. - * ``` - * - * Output: - * - * ``` - * "First line\nSecond line\n\nFourth line\nFifth line\n" - * ``` - * - * **Keyword Argument `chomp`** - * - * With keyword argument `chomp` given as `true` (the default is `false`), - * removes trailing newline (if any) from each line: - * - * ``` - * strio = StringIO.new(TEXT) - * strio.each_line(chomp: true) {|line| p line } - * ``` - * - * Output: - * - * ``` - * "First line" - * "Second line" - * "" - * "Fourth line" - * "Fifth line" - * ``` - * - * With no block given, returns a new {Enumerator}[rdoc-ref:Enumerator]. - * - * Related: StringIO.each_byte, StringIO.each_char, StringIO.each_codepoint. */ static VALUE strio_each(int argc, VALUE *argv, VALUE self) From abf3056381a29847576d9d53242aaec5f7cc1ca4 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sat, 15 Nov 2025 07:48:35 -0600 Subject: [PATCH 2/3] [ruby/stringio] [DOC] Doc for StringIO.size (https://github.com/ruby/stringio/pull/171) https://github.com/ruby/stringio/commit/95a111017a --- ext/stringio/stringio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index e34be661cb8b12..567bdec72e808e 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1843,10 +1843,10 @@ strio_syswrite_nonblock(int argc, VALUE *argv, VALUE self) /* * call-seq: - * strio.length -> integer - * strio.size -> integer + * size -> integer + * + * :include: stringio/size.rdoc * - * Returns the size of the buffer string. */ static VALUE strio_size(VALUE self) From 9e8a661f3baae0b86d5f83ac9719c8d3eb37a077 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sat, 15 Nov 2025 07:50:32 -0600 Subject: [PATCH 3/3] [ruby/stringio] [DOC] Fix #seek link (https://github.com/ruby/stringio/pull/174) Method #seek deserves (and will get) documentation independent of that in class IO. Meanwhile, the link should go someplace sensible and useful. https://github.com/ruby/stringio/commit/d026549719 --- ext/stringio/stringio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 567bdec72e808e..603d9c5e22611e 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -883,9 +883,9 @@ strio_rewind(VALUE self) * call-seq: * seek(offset, whence = SEEK_SET) -> 0 * - * Sets the current position to the given integer +offset+ (in bytes), + * Sets the position to the given integer +offset+ (in bytes), * with respect to a given constant +whence+; - * see {Position}[rdoc-ref:IO@Position]. + * see {IO#seek}[rdoc-ref:IO#seek]. */ static VALUE strio_seek(int argc, VALUE *argv, VALUE self)