From 91c28a721097f833628baf33c914d560b72a08ee Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 27 Oct 2025 17:54:04 +0100 Subject: [PATCH 1/3] [DOC] Doc for StringIO.each_byte --- ext/stringio/stringio.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 5c6568a2..c743291b 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -937,9 +937,41 @@ strio_get_sync(VALUE self) * each_byte {|byte| ... } -> self * * With a block given, calls the block with each remaining byte in the stream; - * see {Byte IO}[rdoc-ref:IO@Byte+IO]. - * - * With no block given, returns an enumerator. + * positions the stream at end-of-file; + * returns +self+: + * + * bytes = [] + * strio = StringIO.new('hello') # Five 1-byte characters. + * strio.each_byte {|byte| bytes.push(byte) } + * strio.eof? # => true + * bytes # => [104, 101, 108, 108, 111] + * bytes = [] + * strio = StringIO.new('тест') # Four 2-byte characters. + * strio.each_byte {|byte| bytes.push(byte) } + * bytes # => [209, 130, 208, 181, 209, 129, 209, 130] + * bytes = [] + * strio = StringIO.new('こんにちは') # Five 3-byte characters. + * strio.each_byte {|byte| bytes.push(byte) } + * bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175] + * + * The position in the stream matters: + * + * bytes = [] + * strio = StringIO.new('hello') + * strio.getc # => "h" + * strio.pos # => 1 + * strio.each_byte {|byte| bytes.push(byte) } + * bytes # => [101, 108, 108, 111] + * + * If at end-of-file, does not call the block: + * + * strio.eof? # => true + * strio.each_byte {|byte| fail 'Boo!' } + * strio.eof? # => true + * + * With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html]. + * + * Related: StringIO.each_char, StringIO.each_codepoint, StringIO.each_line. */ static VALUE strio_each_byte(VALUE self) @@ -1630,7 +1662,7 @@ strio_readline(int argc, VALUE *argv, VALUE self) * "Fifth line" * ``` * - * With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html]. + * With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html]. * * Related: StringIO.each_byte, StringIO.each_char, StringIO.each_codepoint. */ From ec546c8a77bc163779102f461fb3e763cfc39a8b Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Mon, 27 Oct 2025 18:49:35 +0100 Subject: [PATCH 2/3] Improve position example --- ext/stringio/stringio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index c743291b..95baa6f6 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -957,11 +957,11 @@ strio_get_sync(VALUE self) * The position in the stream matters: * * bytes = [] - * strio = StringIO.new('hello') - * strio.getc # => "h" - * strio.pos # => 1 + * strio = StringIO.new('こんにちは') + * strio.getc # => "こ" + * strio.pos # => 3 # 3-byte character was read. * strio.each_byte {|byte| bytes.push(byte) } - * bytes # => [101, 108, 108, 111] + * bytes # => [227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175] * * If at end-of-file, does not call the block: * From e87d2ae3d16ebbbff3c0c5c4271a8cf3ab3b35a7 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 28 Oct 2025 11:41:34 +0900 Subject: [PATCH 3/3] Fix method name separator --- ext/stringio/stringio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 95baa6f6..2903d4ab 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -971,7 +971,7 @@ strio_get_sync(VALUE self) * * With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html]. * - * Related: StringIO.each_char, StringIO.each_codepoint, StringIO.each_line. + * Related: StringIO#each_char, StringIO#each_codepoint, StringIO#each_line. */ static VALUE strio_each_byte(VALUE self)